validate.ts 1.8 KB

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