Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Email Password Validation

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 820
    Comment on it

    Hello Coders,

    It’s always a need to validate email at user end. Not only this but strong password is also suggested to secure accounts.

    Here are snippets to validate if correct email and strong password are entered or not.

     

    //Validating email
    
    func isValidEmail(email:String)->Bool{
    
        let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
    
        let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
    
        return emailTest.evaluate(with: email)
    
      }

     

    Below function will check for the password according to the regex, it’s required to have following condition for strong password

    1- Minimum 8 characters to 24 characters max, you can change the limit as passed in arguments(make sure it's at least 4).

    2- It should have atleast one capital letter.

    3- password should have at least one numeric character.

    4- there must be at least one special character.

    //Validating password 
    func isValidPassword(password:String, minChar:Int = 8, maxChar:Int = 24)->Bool{
    
        let passwordRegEx = "^(?=.*[A-Z])(?=.*[!@#$&*])(?=.*[0-9])(?=.*[a-z]).{\(minChar),\(maxChar)}$"
    
        let passwordTest = NSPredicate(format:"SELF MATCHES %@", passwordRegEx)
    
        return passwordTest.evaluate(with: password)
    
      }

     

    Now you can use above methods and their values accordingly. :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: