Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression for Password validation 1

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
0
0
US
I need to do the password validation in javascript with the below policies. Will you please let me know how the regular expression look like?

- Password should be 6 to 13 character long.
- Password should have at least one alphabet (a-z, A-Z)
- Password should have at least one numeric value(0-9)
- Password should not have special characters.

Thanks in advance.
 
I would suggest it might be easier to use more than 1 RegExp to do this, rather than trying to do it in 1 go.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
I think if it was me I'd do it in two parts too,

first checking for numbers and letters only,between 6 and 13

pass=/^(\d|\w){6,13}$/;

then do the second to just make sure it contains a letter and a number.
 
This regular satisfies all the above conditions.

/^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{5,12}$/;


eg:

var re = /^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{5,12}$/;
if ( !re.test(passwd) )
{
alert('Your password must satisfy the following. \n\n* Password should be 5 to 12 character long. \n* Password should have at least one alphabet. \n* Password should have at least one numeric value. \n* Password should not have special characters.');
return false;
}


Thanks for everybodies time.
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top