Regular expressions are used in day to day programming . . Like validations and scripting , Database Constraints etc . .

Validations – emails , phone etc …

Database – check . . . .email_id like ‘reg_expr’
ex – like ‘123_’
o/p
1231
1233
1234
1235
1236

So Dot.net Supports Regular Expressions on both sides ie ON CLIENT SIDE VALIDATION
AND ON SERVER SIDE VALIDATION ,

Client side – It provides a validation control called RegularExpression Validator

EX- <asp:RegularExpressionValidator id=”revEmail” runat=”server”  ErrorMessage=”Please enter a valid ‘Email ID'”                                         ValidationExpression=”\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”             ControlToValidate=”EMAIL”   ValidationGroup=”CreateUserWizard” Display=”Dynamic” >                                </asp:RegularExpressionValidator>

Server Side –

//include

using System.Text.RegularExpressions;

//define one regular expression and

Regex NaturalNo=new Regex(“[^0-9]”);

//read the value and compare it . .

NaturalNo.IsMatch(yourValue)

Finally it returns bool value . .(true/false) .

Advertisements