tags:

views:

93

answers:

2

hi, I need a regular expression which accepts the alphabets UPPER CASE,lower case and digits minimum character is 5 and maximum character is 20. This is my current Reg Ex.

^[A-Za-z\d]{5,20}$

The issue that i am facing with the current Regular expression is, if i enter 5 spaces it accepts. so i want the user to enter password without space.

+1  A: 

Are you using a RegularExpressionValidator? If so you should add a RequiredFieldValidator to prevent whitespace or blank entries. Per the RegularExpressionValidator documentation:

Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.

Ahmad Mageed
@Ahmed: I am not using Regular expression validator as i am working on ASP.NET MVC.
Nimesh
+1  A: 

another way

 ^[a-zA-Z0-9]{5,20}$
ghostdog74
Which might be more as intended, as most people don't seem to expect that \d matches all kinds of numeric Unicode characters (like Arabic numberals and such), as far as I know.
peSHIr
@peSHIr - Thanks for point it out, didn't know \d matches Unicode. By the chance you can give me an example?
Jay Zeng