validate.js 562 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @param {string} path
  3. * @returns {Boolean}
  4. */
  5. export function isExternal(path) {
  6. return /^(https?:|mailto:|tel:)/.test(path)
  7. }
  8. /**
  9. * @param {string} email
  10. * @returns {Boolean}
  11. */
  12. export function validEmail(email) {
  13. return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email)
  14. }
  15. /**
  16. * @param {string} code
  17. * @returns {Boolean}
  18. */
  19. export function validCode(code) {
  20. return /^[0-9]{6}$/.test(code)
  21. }
  22. /**
  23. * @param {string} pwd
  24. * @returns {Boolean}
  25. */
  26. export function validPwd(pwd) {
  27. return /^[a-zA-Z]\w{5,7}$/.test(pwd)
  28. }