verify.js 1.2 KB

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