Guest User

Untitled

a guest
Feb 14th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import Foundation
  2.  
  3. class InputsValidationService {
  4.  
  5. // No special characters (e.g. @,#,$,%,&,*,(,),^,<,>,!,±)
  6. // Only letters, underscores and numbers allowed
  7. // Length should be 18 characters max and 3 characters minimum
  8. static func isValid(username:String) -> Bool {
  9. let regEx = "\\A\\w{3,18}\\z"
  10. let pred = NSPredicate(format:"SELF MATCHES %@", regEx)
  11. return pred.evaluate(with:username)
  12. }
  13.  
  14. // There’s some text before the @
  15. // There’s some text after the @
  16. // There’s at least 2 alpha characters after a .
  17. static func isValid(email:String?) -> Bool {
  18. guard email != nil else { return false }
  19. let regEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
  20. let pred = NSPredicate(format:"SELF MATCHES %@", regEx)
  21.  
  22. return pred.evaluate(with: email)
  23. }
  24.  
  25. // at least one uppercase,
  26. // at least one digit
  27. // at least one lowercase
  28. // 6 characters total
  29. static func isValid(password:String?) -> Bool {
  30. guard password != nil else { return false }
  31. let pred = NSPredicate(format: "SELF MATCHES %@", "(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{6,}")
  32. return pred.evaluate(with: password)
  33. }
  34. }
Add Comment
Please, Sign In to add comment