Powered By Blogger

Thursday, December 17, 2009

Regular Expression in asp.net


This table lists the regular expressions which were used in this sample code, the data type each is intended to recognize, and some examples of strings that each regular expression accepts (matches) and rejects (does not match).

data type regular expression accepts rejects
whitespace /^\s+$/ spaces, tabs, etc. 0 a
single letter /^[a-zA-Z]$/ a A 0 . -
alphabetic string /^[a-zA-Z]+$/ aAbB a1 23
single digit /^\d/ 0 00 1a
single letter or digit /^([a-zA-Z]|\d)$/ 0 a 00 1a
alphanumeric string /^[a-zA-Z0-9]+$/ a1b2 2.5 1.a
integer /^\d+$/ 0 23 23.5
signed integer /^(+|-)?\d+$/ -1 +12 -1.1
floating point number /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/ 1.1 .9 8. -1.1 .
signed float /^(((+|-)?\d+(\.\d*)?)|((+|-)?(\d*\.)?\d+))$/ -1.1 1.1 .9 8. 1a
email address /^.+\@.+\..+$/ a@b.c a@b




No comments:

Post a Comment