You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

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