validate.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * 函数节流
  57. * @param fn
  58. * @param interval
  59. * @returns {Function}
  60. * @constructor
  61. */
  62. export const Throttle = (fn, t) => {
  63. let last
  64. let timer
  65. const interval = t || 500
  66. return function() {
  67. const args = arguments
  68. const now = +new Date()
  69. if (last && now - last < interval) {
  70. clearTimeout(timer)
  71. timer = setTimeout(() => {
  72. last = now
  73. fn.apply(this, args)
  74. }, interval)
  75. } else {
  76. last = now
  77. fn.apply(this, args)
  78. }
  79. }
  80. }