Rap 原分销系统代码Web
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

168 wiersze
4.1KB

  1. /**
  2. * Created by PanJiaChen on 16/11/18.
  3. */
  4. /**
  5. * @param {string} path
  6. * @returns {Boolean}
  7. */
  8. export function isExternal(path) {
  9. return /^(https?:|mailto:|tel:)/.test(path)
  10. }
  11. /**
  12. * @param {string} str
  13. * @returns {Boolean}
  14. */
  15. export function validUsername(str) {
  16. const valid_map = ['admin', 'editor']
  17. return valid_map.indexOf(str.trim()) >= 0
  18. }
  19. /**
  20. * @param {string} url
  21. * @returns {Boolean}
  22. */
  23. export function validURL(url) {
  24. const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  25. return reg.test(url)
  26. }
  27. /**
  28. * @param {string} str
  29. * @returns {Boolean}
  30. */
  31. export function validLowerCase(str) {
  32. const reg = /^[a-z]+$/
  33. return reg.test(str)
  34. }
  35. /**
  36. * @param {string} str
  37. * @returns {Boolean}
  38. */
  39. export function validUpperCase(str) {
  40. const reg = /^[A-Z]+$/
  41. return reg.test(str)
  42. }
  43. /**
  44. * @param {string} str
  45. * @returns {Boolean}
  46. */
  47. export function validAlphabets(str) {
  48. const reg = /^[A-Za-z]+$/
  49. return reg.test(str)
  50. }
  51. /**
  52. * @param {string} email
  53. * @returns {Boolean}
  54. */
  55. export function validEmail(email) {
  56. const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  57. return reg.test(email)
  58. }
  59. export function isvalidPhone(phone) {
  60. const reg = /^1([38][0-9]|4[014-9]|[59][0-35-9]|6[2567]|7[0-8])\d{8}$/
  61. return reg.test(phone)
  62. }
  63. /**
  64. * @param {string} str
  65. * @returns {Boolean}
  66. */
  67. export function isString(str) {
  68. if (typeof str === 'string' || str instanceof String) {
  69. return true
  70. }
  71. return false
  72. }
  73. /**
  74. * @param {Array} arg
  75. * @returns {Boolean}
  76. */
  77. export function isArray(arg) {
  78. if (typeof Array.isArray === 'undefined') {
  79. return Object.prototype.toString.call(arg) === '[object Array]'
  80. }
  81. return Array.isArray(arg)
  82. }
  83. /**
  84. * 是否合法IP地址
  85. * @param rule
  86. * @param value
  87. * @param callback
  88. */
  89. export function validateIP(rule, value, callback) {
  90. if (value === '' || value === undefined || value == null) {
  91. callback()
  92. } else {
  93. const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
  94. if ((!reg.test(value)) && value !== '') {
  95. callback(new Error('请输入正确的IP地址'))
  96. } else {
  97. callback()
  98. }
  99. }
  100. }
  101. /* 是否手机号码或者固话*/
  102. export function validatePhoneTwo(rule, value, callback) {
  103. const reg = /^((0\d{2,3}-\d{7,8})|(1([38][0-9]|4[014-9]|[59][0-35-9]|6[2567]|7[0-8])\d{8}))$/
  104. if (value === '' || value === undefined || value == null) {
  105. callback()
  106. } else {
  107. if ((!reg.test(value)) && value !== '') {
  108. callback(new Error('请输入正确的电话号码或者固话号码'))
  109. } else {
  110. callback()
  111. }
  112. }
  113. }
  114. /* 是否固话*/
  115. export function validateTelephone(rule, value, callback) {
  116. const reg = /0\d{2}-\d{7,8}/
  117. if (value === '' || value === undefined || value == null) {
  118. callback()
  119. } else {
  120. if ((!reg.test(value)) && value !== '') {
  121. callback(new Error('请输入正确的固话(格式:区号+号码,如010-1234567)'))
  122. } else {
  123. callback()
  124. }
  125. }
  126. }
  127. /* 是否手机号码*/
  128. export function validatePhone(rule, value, callback) {
  129. const reg = /^1([38][0-9]|4[014-9]|[59][0-35-9]|6[2567]|7[0-8])\d{8}$/
  130. if (value === '' || value === undefined || value == null) {
  131. callback()
  132. } else {
  133. if ((!reg.test(value)) && value !== '') {
  134. callback(new Error('请输入正确的电话号码'))
  135. } else {
  136. callback()
  137. }
  138. }
  139. }
  140. /* 是否身份证号码*/
  141. export function validateIdNo(rule, value, callback) {
  142. const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  143. if (value === '' || value === undefined || value == null) {
  144. callback()
  145. } else {
  146. if ((!reg.test(value)) && value !== '') {
  147. callback(new Error('请输入正确的身份证号码'))
  148. } else {
  149. callback()
  150. }
  151. }
  152. }