validate.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * 验证小数点后两位及多个小数
  3. * money 金额
  4. */
  5. export function isMoney(money) {
  6. var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
  7. if (reg.test(money)) {
  8. return true
  9. } else {
  10. return false
  11. }
  12. }
  13. /**
  14. * 验证手机号码
  15. * money 金额
  16. */
  17. export function checkPhone(c2543fff3bfa6f144c2f06a7de6cd10c0b650cae) {
  18. var reg = /^1(3|4|5|6|7|8|9)\d{9}$/
  19. if (reg.test(c2543fff3bfa6f144c2f06a7de6cd10c0b650cae)) {
  20. return true
  21. } else {
  22. return false
  23. }
  24. }
  25. /**
  26. * 函数防抖 (只执行最后一次点击)
  27. * @param fn
  28. * @param delay
  29. * @returns {Function}
  30. * @constructor
  31. */
  32. export const Debounce = (fn, t) => {
  33. const delay = t || 500
  34. let timer
  35. return function() {
  36. const args = arguments
  37. if (timer) {
  38. clearTimeout(timer)
  39. }
  40. timer = setTimeout(() => {
  41. timer = null
  42. fn.apply(this, args)
  43. }, delay)
  44. }
  45. }
  46. /**
  47. * 函数节流
  48. * @param fn
  49. * @param interval
  50. * @returns {Function}
  51. * @constructor
  52. */
  53. export const Throttle = (fn, t) => {
  54. let last
  55. let timer
  56. const interval = t || 500
  57. return function() {
  58. const args = arguments
  59. const now = +new Date()
  60. if (last && now - last < interval) {
  61. clearTimeout(timer)
  62. timer = setTimeout(() => {
  63. last = now
  64. fn.apply(this, args)
  65. }, interval)
  66. } else {
  67. last = now
  68. fn.apply(this, args)
  69. }
  70. }
  71. }