By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

Help generating Regular Expression

P: 1
I want to generate a regular expression for password check.(ASP.Net)
But javascript is what it really is.
I would like to enforce Minimum 6 alphanumeric characters with minimum 1 numeric(0-9) and 1 character(a-z) or 1 Special Character(. or _)
So far I have been able to generate something so they enter 6 alpha numberic characters, but don't know a way to check presence of 1 numeric and 1 alpha-numeric characted(or special).


Please help.
Dec 30 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 213
I think the best way to do that is by doing three checks, it may be able to do that in one single regexp pattern, but I think it's not worth the time and effort, you can do this:

Expand|Select|Wrap|Line Numbers
  1. //the following string will validate, while if it only has numbers or only letters, it won't
  2. var s = 'a.b123-ic83_87s';
  4. if( s.match(/^[\w\._-]{6,}$/i) ) { //any word character, dashm dot or underscore, minimum 6 chars
  5.    if( s.match(/([a-z]+)/i) && s.match(/([0-9]+)/i) ) { //if it contains at least a number AND a letter
  6.       alert('ok');
  7.    }
  8. }
Dec 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.