validate.js 1.2 KB

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