Password Validation in swift 3.0.

In this tutorial we are sturdy about the password validation in swift. There are too many validation for password. Most of the validation is password and confirm password is same, Password must have more then some characters , Password contain some special character , Password must one digit , Password must one uppercase letter. etc.


Here you are study these tutorial of password validation carefully, After you can also make your own validation for password. 

Password Validation Type - 1 

1 - Password length is 8.
2 - One Alphabet in Password.
3 - One Special Character in Password. 


Explanation:

^                              - Start Anchor.
(?=.*[a-z])              -Ensure string has one character.
(?=.[$@$#!%?&])   -Ensure string has one special character.
{8,}                            -Ensure password length is 8.
$                               -End Anchor. 
Code : 
func isPasswordValid(_ password : String) -> Bool{
    let passwordTest = NSPredicate(format: "SELF MATCHES %@", "^(?=.*[a-z])(?=.*[$@$#!%*?&])[A-Za-z\\d$@$#!%*?&]{8,}")
    return passwordTest.evaluate(with: password)
}

Password Validation Type - 2 

1 - Password length is 8.
2 - 2 UpperCase letters in Password.
3 - One Special Character in Password.
4 - Two Number in Password.
5- Three letters of lowercase in password. 

Explanation:

^                                                          -Start Anchor.
(?=.*[A-Z].*[A-Z])                            -Ensure string has two uppercase letters.
(?=.[$@$#!%?&])                                -Ensure string has one special character.
(?=.*[0-9].*[0-9])                              -Ensure string has two digits.
(?=.*[a-z].*[a-z].?*[a-z])                 -Ensure string has three lowercase letters.
{8,}                                                         -Ensure password length is 8.
$                                                          -End Anchor. 
Code : 
func isPasswordValid(_ password : String) -> Bool{
    let passwordTest = NSPredicate(format: "SELF MATCHES %@", "^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$")
    return passwordTest.evaluate(with: password)
}

You Can See more validation like Email-Validation , Phone-Number , Password Validation Also. 

Thanks.

Password Validation in swift 3.0. Password Validation in swift 3.0. Reviewed by Kirit Modi on 03:28:00 Rating: 5

No comments:

Powered by Blogger.