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.
 
 
 
 

45 lines
1.1 KiB

  1. /// Password should have,
  2. /// at least a upper case letter
  3. /// at least a lower case letter
  4. /// at least a digit
  5. /// at least a special character [@#$%^&+=]
  6. /// length of at least 4
  7. /// no white space allowed
  8. bool isValidPassword(String? inputString, {bool isRequired = false}) {
  9. bool isInputStringValid = false;
  10. if ((inputString == null ? true : inputString.isEmpty) && !isRequired) {
  11. isInputStringValid = true;
  12. }
  13. if (inputString != null) {
  14. const pattern =
  15. r'^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$';
  16. final regExp = RegExp(pattern);
  17. isInputStringValid = regExp.hasMatch(inputString);
  18. }
  19. return isInputStringValid;
  20. }
  21. /// Checks if string consist only Alphabet. (No Whitespace)
  22. bool isText(String? inputString, {bool isRequired = false}) {
  23. bool isInputStringValid = false;
  24. if ((inputString == null ? true : inputString.isEmpty) && !isRequired) {
  25. isInputStringValid = true;
  26. }
  27. if (inputString != null) {
  28. const pattern = r'^[a-zA-Z]+$';
  29. final regExp = RegExp(pattern);
  30. isInputStringValid = regExp.hasMatch(inputString);
  31. }
  32. return isInputStringValid;
  33. }