utils.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //身份证校验
  2. function IdentityCodeValid(code:string) {
  3. let m = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/
  4. return m.test(code)
  5. }
  6. // 手机号校验
  7. function isPoneAvailable(poneInput:string) {
  8. var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  9. if (!myreg.test(poneInput)) {
  10. return false;
  11. } else {
  12. return true;
  13. }
  14. }
  15. // 身份证号获取出生年月日
  16. function getBirthdatByIdNo(iIdNo:string) {
  17. var tmpStr = "";
  18. iIdNo = iIdNo.replace(/^\s+|\s+$/g, "");
  19. if (iIdNo.length == 15) {
  20. tmpStr = iIdNo.substring(6, 12);
  21. tmpStr = "19" + tmpStr;
  22. tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
  23. } else {
  24. tmpStr = iIdNo.substring(6, 14);
  25. tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
  26. }
  27. return tmpStr;
  28. }
  29. // 获取性别
  30. function getSex(idcard:string) {
  31. let sex = ''
  32. if (parseInt(idcard.substr(16, 1)) % 2 == 1) {
  33. sex = '男'
  34. } else {
  35. sex = '女'
  36. }
  37. return sex
  38. }
  39. // 微信号校验
  40. function authCode(str:string){
  41. let length = str.replace(/\s/g,"").length
  42. return length
  43. }
  44. export const fun = {
  45. IdentityCodeValid,
  46. isPoneAvailable,
  47. getBirthdatByIdNo,
  48. getSex,
  49. authCode
  50. }