basicInspection.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* 去除字符串中的特殊符号 */
  2. const queryStr = (str, title = '该符号不可输入!') => {
  3. const pattern = new RegExp(/[`$%^&()\=<>"{}|\/;'\\[\]·%……&——\={}|]/g);
  4. if (pattern.test(str) == true && title) wx.showToast({
  5. title,
  6. icon: "none"
  7. })
  8. return str.replace(pattern, '');
  9. }
  10. /* 校验手机号码 */
  11. const CheckPhoneNumber = (num, title = '请输入正确的11位手机号码!') => {
  12. const reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
  13. let isAllow = reg.test(num);
  14. if (!isAllow && title) wx.showToast({
  15. title,
  16. icon: "none"
  17. })
  18. return isAllow;
  19. }
  20. /* 校验邮箱 */
  21. const CheckEmail = (num, title = '请输入正确的邮箱格式!') => {
  22. const reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  23. let isAllow = reg.test(num);
  24. if (!isAllow && title) wx.showToast({
  25. title,
  26. icon: "none"
  27. })
  28. return isAllow;
  29. }
  30. module.exports = {
  31. queryStr,
  32. CheckPhoneNumber,
  33. CheckEmail
  34. }