C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to write validationexpression for a RegularExpressionValidator


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: vivekMember Level: Bronze    
Rating: Points: 10



The following code sample shows how to write validationexpression for a RegularExpressionValidator

Email validation

<asp:TextBox ID="txtEmail" runat="Server" Columns="40" />
<asp:RegularExpressionValidator ID="revemail" runat="server" ControlToValidate="txtEmail" ErrorMessage="Eg:abcde@abc.ad" validationexpression="^.+\@.+\..+$" Display="static" SetFocusOnError="true"></asp:RegularExpressionValidator>

Pincode validation

<asp:TextBox ID="txtPincode" runat="Server" Columns="40" />
<asp:RegularExpressionValidator ID="revPincode" runat="server" ControlToValidate="txtPincode" ErrorMessage="enter correct pincode" validationexpression="^.+\@.+\..+$" Display="static" SetFocusOnError="true"></asp:RegularExpressionValidator>

validating password and confirm password

<asp:TextBox ID="TextBox3" runat="Server" TextMode="Password" Columns="40" />
<asp:TextBox ID="textbox2" runat="Server" TextMode="Password" Columns="40" />
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Passwords don't match!" ControlToValidate="TextBox3"
ControlToCompare="textbox2" ></asp:CompareValidator>

Validating year

<asp:TextBox ID="txtValidityDate" runat="server" />
<asp:RegularExpressionValidator ID="revvaliditydate" runat="server" ControlToValidate="txtValidityDate" ErrorMessage="Date Format(dd/mm/yyyy)"
ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$" Display="static" SetFocusOnError="true"></asp:RegularExpressionValidator>

Validation For 999-99-9999 Format

ValidationExpression="(^\d{3}\-?\d{2}\-?\d{4}$)"

Validation For(555) 555-5555 Format

ValidationExpression="(^((\(?\d{3}\))|(\d{3}))?\s?\d{3}[\-.]?\d{4}$)"




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to Draw SerpinskiTriangle in Asp.net
Previous Resource: How to set ToolTip for a button in C#
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use