Tuesday, December 28, 2010

Regular expression in Asp.net

regular expressions, also referred to as regex or regexp, provide a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.

Sample regular Expressions:-


//Regular Expression for All Use


Accept only string
Ex:-
ValidationExpression ="^([ \u00c0-\u01ffa-zA-'])+$"

Accept Only Email
Ex:-
ValidationExpression ="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"


Accept Only Integer
Ex:-
ValidationExpression="(\d+)"

Accept 5 no’s only
Ex:-
ValidationExpression="^[0-9]{5}$"


Accept Only Date Formate----mm/dd/yyyy
Ex:-
([1-9]|1[012])[- /.]([1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

Accept Only Date Formate---- DD/MM/YYYY
Ex:-
ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[-/.](19|20)\d\d"

Accept Only 2 decimal points
Ex:-
ValidationExpression="^\$?\d{1,3}(\,?\d{3})*(\.\d{2})?$" --it’s for getting valid

No comments: