verify.js 1.1 KB

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