validate.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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|6|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 (/dev/.test(url)) { // dev 环境
  29. returnUrl = 'http://mstudev.dayaedu.com'
  30. } else if (/online/.test(url)) { //线上
  31. returnUrl = 'https://mstuonline.dayaedu.com'
  32. } else { // 默认dev环境
  33. returnUrl = 'http://mstudev.dayaedu.com'
  34. }
  35. return returnUrl
  36. }
  37. // 老师地址
  38. export function vaildTeacherUrl() {
  39. let url = window.location.href
  40. let returnUrl = ''
  41. if (/dev/.test(url)) { // dev 环境
  42. returnUrl = 'http://mteadev.dayaedu.com'
  43. } else if (/online/.test(url)) { //线上
  44. returnUrl = 'https://mteaonline.dayaedu.com'
  45. } else { // 默认dev环境
  46. returnUrl = 'http://mteadev.dayaedu.com'
  47. }
  48. return returnUrl
  49. }
  50. export function nextMonthLastDay(year, month) { //日期显示为次月最后一天
  51. // var time = date ? new Date(date) : new Date();
  52. // var year = time.getFullYear();
  53. // //var year = 1900; //用于测试
  54. // var month = time.getMonth() + 2;
  55. if (month > 12) {
  56. month = month - 12;
  57. year = year + 1;
  58. }
  59. var day = nextMonthDay(year, month);
  60. return [year, month, day];
  61. }
  62. function nextMonthDay(year, month) { //判断每月多少天
  63. var day31 = [1, 3, 5, 7, 8, 10, 12];
  64. var day30 = [4, 6, 9, 11];
  65. if (day31.indexOf(month) > -1) {
  66. return 31;
  67. } else if (day30.indexOf(month) > -1) {
  68. return 30;
  69. } else {
  70. if (isLeapYear(year)) {
  71. return 29;
  72. } else {
  73. return 28;
  74. }
  75. }
  76. }
  77. function isLeapYear(year) { //判断是否为闰年
  78. return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
  79. }