validate.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Created by jiachenpan on 16/11/18.
  3. */
  4. /* 合法uri*/
  5. export function validateURL(textval) {
  6. const urlregex = /^(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 urlregex.test(textval)
  8. }
  9. /* 小写字母*/
  10. export function validateLowerCase(str) {
  11. const reg = /^[a-z]+$/
  12. return reg.test(str)
  13. }
  14. /* 大写字母*/
  15. export function validateUpperCase(str) {
  16. const reg = /^[A-Z]+$/
  17. return reg.test(str)
  18. }
  19. /* 大小写字母*/
  20. export function validatAlphabets(str) {
  21. const reg = /^[A-Za-z]+$/
  22. return reg.test(str)
  23. }
  24. /**
  25. * validate email
  26. * @param email
  27. * @returns {boolean}
  28. */
  29. export function validateEmail(email) {
  30. const re = /^(([^<>()\[\]\\.,;:\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,}))$/
  31. return re.test(email)
  32. }