validate.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Created by PanJiaChen on 16/11/18.
  3. */
  4. /**
  5. * @param {string} path
  6. * @returns {Boolean}
  7. */
  8. export function isExternal(path) {
  9. return /^(https?:|mailto:|tel:)/.test(path)
  10. }
  11. /**
  12. * @param {string} str
  13. * @returns {Boolean}
  14. */
  15. export function validUsername(str) {
  16. const valid_map = ['admin', 'editor']
  17. return valid_map.indexOf(str.trim()) >= 0
  18. }
  19. // 手机号验证
  20. export function isvalidPhone(str) {
  21. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
  22. return reg.test(str)
  23. }
  24. // 学生地址
  25. export function vaildStudentUrl() {
  26. let url = window.location.href
  27. let returnUrl = ''
  28. if(/test/.test(url)) { // test环境
  29. returnUrl = 'http://mstutest.dayaedu.com'
  30. } else if(/dev/.test(url)) { // dev 环境
  31. returnUrl = 'http://mstudev.dayaedu.com'
  32. } else if(/online/.test(url)) { //线上
  33. returnUrl = 'https://mstuonline.dayaedu.com'
  34. } else { // 默认dev环境
  35. returnUrl = 'http://mstudev.dayaedu.com'
  36. }
  37. return returnUrl
  38. }
  39. // 老师地址
  40. export function vaildTeacherUrl() {
  41. let url = window.location.href
  42. let returnUrl = ''
  43. if(/test/.test(url)) { // test环境
  44. returnUrl = 'http://mteatest.dayaedu.com'
  45. } else if(/dev/.test(url)) {// dev 环境
  46. returnUrl = 'http://mteadev.dayaedu.com'
  47. } else if(/online/.test(url)) {//线上
  48. returnUrl = 'https://mteaonline.dayaedu.com'
  49. } else { // 默认dev环境
  50. returnUrl = 'http://mteadev.dayaedu.com'
  51. }
  52. return returnUrl
  53. }