validate.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. /**
  11. * 验证小数点后两位及多个小数
  12. * money 金额
  13. */
  14. export function isMoney(money) {
  15. var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
  16. if (reg.test(money)) {
  17. return true
  18. } else {
  19. return false
  20. }
  21. }
  22. /**
  23. * 验证手机号码
  24. * money 金额
  25. */
  26. export function checkPhone(c2543fff3bfa6f144c2f06a7de6cd10c0b650cae) {
  27. var reg = /^1(3|4|5|6|7|8|9)\d{9}$/
  28. if (reg.test(c2543fff3bfa6f144c2f06a7de6cd10c0b650cae)) {
  29. return true
  30. } else {
  31. return false
  32. }
  33. }
  34. /**
  35. * 函数防抖 (只执行最后一次点击)
  36. * @param fn
  37. * @param delay
  38. * @returns {Function}
  39. * @constructor
  40. */
  41. export const Debounce = (fn, t) => {
  42. const delay = t || 500
  43. let timer
  44. return function() {
  45. const args = arguments
  46. if (timer) {
  47. clearTimeout(timer)
  48. }
  49. timer = setTimeout(() => {
  50. timer = null
  51. fn.apply(this, args)
  52. }, delay)
  53. }
  54. }
  55. // 节流函数
  56. export function throttle(fn, delay) {
  57. var lastArgs;
  58. var timer;
  59. var delay = delay || 200;
  60. return function(...args) {
  61. lastArgs = args;
  62. if(!timer){
  63. timer = setTimeout(()=>{
  64. timer = null;
  65. fn.apply(this, lastArgs);
  66. }, delay);
  67. }
  68. }
  69. }