Here we are going to write a regular exprestion for Password to check the condition like , password must contain at least one number,one capital letter and one special character.
First we can write Regex as below,
^(((.*\d.*[A-Z].*[!@#$%^&*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&*? ~].*)|(.*[!@#$%^&*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&*? ~].*\d.*[A-Z].*))$
This will check the string contain at at least one number,one capital letter and one special character,
Here i am going to show examples with Javascript function ,
We can write a function in javascript as below
function validatePassword(str) { // patter to match : Atleast one number ,one capital letter, one special charector var reg = /^(((.*\d.*[A-Z].*[!@#$%^&*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&*? ~].*)|(.*[!@#$%^&*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&*? ~].*\d.*[A-Z].*))$/; if (reg.test(str)) { return true; } else { return false; } }
and we can pass the string as function argument “str”, It will return if it matches the condition else it will return false.
Let us look on the demo
Javascript function sample
Let us look a jquery demo
Jquery sample
You can download from github
Have a noce day 😉
13,414 total views, 4 views today
January 1, 2016 at 9:07 pm
Thanks so much for the blog post.Thanks Again. Great.
February 1, 2016 at 9:47 pm
Thanks for the blog post.Really looking forward to read more. Really Cool.
February 21, 2017 at 6:16 pm
Thanks again for the article post.Thanks Again. Keep writing.