validate.js 965 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * @param {string} url
  3. * @returns {Boolean}
  4. */
  5. export function validURL(url) {
  6. 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.,?'\\+&%$#=~_-]+))*$/
  7. return reg.test(url)
  8. }
  9. /**
  10. * @param {string} email
  11. * @returns {Boolean}
  12. */
  13. export function validEmail(email) {
  14. 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,}))$/
  15. return reg.test(email)
  16. }
  17. /**
  18. * 校验是否是手机号码
  19. * @param mobile
  20. * @returns {boolean}
  21. */
  22. export function isMobile(mobile) {
  23. const regx = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  24. return regx.test(mobile)
  25. }