validate.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // 学员地址
  2. export function vaildStudentUrl() {
  3. const url = window.location.hostname;
  4. let returnUrl = '';
  5. if (/dev/.test(url)) {
  6. // dev 环境
  7. returnUrl = 'https://dev.gym.lexiaoya.cn/mdaya';
  8. } else if (/test/.test(url)) {
  9. // dev 环境
  10. returnUrl = 'https://test.gym.lexiaoya.cn/mdaya';
  11. } else {
  12. // 默认线上环境
  13. returnUrl = 'https://gym.lexiaoya.cn/mdaya';
  14. }
  15. return returnUrl;
  16. }
  17. // 当前
  18. export function vaildCurrentUrl() {
  19. const url = window.location.hostname;
  20. let returnUrl = '';
  21. if (/dev/.test(url)) {
  22. // dev 环境
  23. returnUrl = 'https://dev.gym.lexiaoya.cn';
  24. } else if (/test/.test(url)) {
  25. // dev 环境
  26. returnUrl = 'https://test.gym.lexiaoya.cn';
  27. } else {
  28. // 默认线上环境
  29. returnUrl = 'https://gym.lexiaoya.cn';
  30. }
  31. return returnUrl;
  32. }
  33. export function checkPhone(phone: string) {
  34. const phoneRule = /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\d{8}$/;
  35. return phoneRule.test(phone);
  36. }
  37. // 身份证号验证
  38. export function checkIDCard(idCardNo?: string) {
  39. let result = true;
  40. //
  41. const idCardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  42. if (idCardReg.test(idCardNo || '') === false) {
  43. result = false;
  44. }
  45. return result;
  46. }
  47. // 港澳居民来往内地通行证(回乡证)
  48. export function checkPassport(idCardNo: string) {
  49. // 港澳居民来往内地通行证
  50. // 规则: H/M + 10位或6位数字
  51. // 样本: H1234567890
  52. let result = true;
  53. // let idReg = /^[mMhH]\\d{10}|[mMhH]\\d{8}$/
  54. const idReg = /^([A-Z]\d{6,10}(\(\w{1}\))?)$/;
  55. if (idReg.test(idCardNo) === false) {
  56. result = false;
  57. }
  58. return result;
  59. }
  60. // 台湾居民来往大陆通行证(台胞证)
  61. export function checkPassportTaiwan(idCardNo: string) {
  62. // 台湾居民来往大陆通行证
  63. // 规则: 新版8位或18位数字, 旧版10位数字 + 英文字母
  64. // 样本: 12345678 或 1234567890B
  65. let result = true
  66. const idReg = /(^\\d{8}$)|(^[a-zA-Z0-9]{10}$)|(^\\d{18}$)/;
  67. if (idReg.test(idCardNo) === false) {
  68. result = false;
  69. }
  70. return result;
  71. }