Regular expression in asp.net using Validator control

  • Thread starter Thread starter Rahul
  • Start date Start date
R

Rahul

I am using Validator control in Asp.net in my Log On page.
and using a Regularexpression property of the control.

My requirement is to have a password that would have
1) atleast one alphabet
2) atleast one numeric
3) can use [Not Necessary] special characters.

I have tried various combinations of using the regular expressions and
I came up with

^.*(?=.*\d)(?=.*[a-zA-Z]).*$

by using this i am able to acheive the above 3 conditions , But I also
see that i can enter spaces in the password fields, which is not
correct.

I have a set of special characters that can only be entered if at all
they are entered.

for.e.g only allow @#$%^&+=
please note that the combination can occur in any sequence.

for e.g
1) abc123%^
2)123abcdef -- This is correct as 1 alphabet and 1numeric is must.
3)^ghf%678
4)abn^78%7

would really appreciate any help.Please also note that i dont want to
call any Javascript function.I only need to provide a correct regex
expression to the property of the Validator control.

Thanks
Sweety
 
I did an MSN search for "regular expression password" and came up with
http://davidhayden.com/blog/dave/archive/2004/09/25/501.aspx which says
this might be a good one, and I like it too:

^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

You indicate that you don't want passwords to contain spaces? Why not?
That's just as valid of a character as any other...
One thing that you may want to watch out for is that you will need a
RequiredFieldValidator in addition to your RegularExpressionValidator
because without it people can submit empty fields since
RegularExpressionValidators always pass on empty inputs by design.
 
Back
Top