ASP.net validators
From Summa Bergania
A list of common types of form input to check with ASP.net validators
[edit]
RegularExpressionValidator
You will have to use RequiredFieldValidator to make the field required, since RegularExpressionValidators will not fail on empty input. The RegularExpressionValidators automatically force matching from beginning to end (i.e. automatically append a leading ^ and trailing $), so all the input has to conform to the expression or it will fail.
| Expression | Explanation | Notes | |
|---|---|---|---|
| Dollar Amount | (\d*)([.]?)(\d{0,2}) | (0+ digits) (optional decimal point) (0-2 digits) | Won't accept commas for thousands |
| Unsigned integers | (\d*) | (0+ digits) | Useful for check numbers, etc |
| Full Name | (\w+)([.]?)(\w*)([.]?)(\w*)([.]?)([ ])(\w+)(.*) | (1+ word characters [a-zA-Z_0-9]) (a space) (1+ word characters) | The ([.]?)(\w*) groups are for names like "G.E.M. Anscombe" and the (.*) is in case they use middle names, initials, suffixes, hyphens, etc. |
| Zip Code | (\d{5})(-\d{4})? | (5 digits) (optional hyphen and 4 digits) | Can drop the (-\d{4})? part for just 5-digit Zips |
| Year | (\d{2})(\d{2})? | (2 digits or 4 digits) | Probably want to convert the 2-digit year into a 4-digit upon submission (or use Microsoft's default interpretation) |
| Credit Card Number | (\d)([0-9 ]{12})([0-9 ]*) | (1 digit) (12+ more digits/spaces) | Some Visa cards only have 13 digits, which is the fewest in the industry. Since this expression accepts spaces, the app will have to remove them. |
[edit]
CompareValidator
| Operator | Type | Notes | |
|---|---|---|---|
| Date | DataTypeCheck | Date | Does verify that it is a real date (i.e. fails for November 31st) |
