validate.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. }
  54. export function nextMonthLastDay(year, month) { //日期显示为次月最后一天
  55. // var time = date ? new Date(date) : new Date();
  56. // var year = time.getFullYear();
  57. // //var year = 1900; //用于测试
  58. // var month = time.getMonth() + 2;
  59. if (month > 12) {
  60. month = month - 12;
  61. year = year + 1;
  62. }
  63. var day = nextMonthDay(year, month);
  64. return [year, month, day];
  65. }
  66. function nextMonthDay(year, month) { //判断每月多少天
  67. var day31 = [1, 3, 5, 7, 8, 10, 12];
  68. var day30 = [4, 6, 9, 11];
  69. if (day31.indexOf(month) > -1) {
  70. return 31;
  71. } else if (day30.indexOf(month) > -1) {
  72. return 30;
  73. } else {
  74. if (isLeapYear(year)) {
  75. return 29;
  76. } else {
  77. return 28;
  78. }
  79. }
  80. }
  81. function isLeapYear(year) { //判断是否为闰年
  82. return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
  83. }