verify.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * 验证类
  3. */
  4. module.exports = {
  5. /**
  6. * 是否为空
  7. */
  8. isEmpty(str) {
  9. return str.trim() == '';
  10. },
  11. /**
  12. * 匹配2代身份证
  13. */
  14. isIdCard(str){
  15. return /^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}[\dXx]$/g.test(str);
  16. },
  17. /**
  18. * 匹配是否金额
  19. */
  20. isMoney(str){
  21. return /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(str);
  22. },
  23. /**
  24. * 匹配phone
  25. */
  26. isPhone(str) {
  27. let reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
  28. return reg.test(str);
  29. },
  30. /**
  31. * 匹配6-32位密码
  32. */
  33. isPws(str) {
  34. return /^.{6,32}$/.test(str);
  35. },
  36. /**
  37. * 匹配Email地址
  38. */
  39. isEmail(str) {
  40. if (str == null || str == "") return false;
  41. var result = str.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
  42. if (result == null) return false;
  43. return true;
  44. },
  45. /**
  46. * 判断数值类型,包括整数和浮点数
  47. */
  48. isNumber(str) {
  49. if (this.isDouble(str) || this.isInteger(str)) return true;
  50. return false;
  51. },
  52. /**
  53. * 判断是否为正整数(只能输入数字[0-9])
  54. */
  55. isPositiveInteger(str) {
  56. return /(^[0-9]\d*$)/.test(str);
  57. },
  58. /**
  59. * 匹配integer
  60. */
  61. isInteger(str) {
  62. if (str == null || str == "") return false;
  63. var result = str.match(/^[-\+]?\d+$/);
  64. if (result == null) return false;
  65. return true;
  66. },
  67. /**
  68. * 匹配double或float
  69. */
  70. isDouble(str) {
  71. if (str == null || str == "") return false;
  72. var result = str.match(/^[-\+]?\d+(\.\d+)?$/);
  73. if (result == null) return false;
  74. return true;
  75. },
  76. };