ASP.net Validation

Life is 10% what happens to us and 90% how we react to it. If you don't build your dream, someone else will hire you to help them build theirs.

ASP.net Validation

Required text validation:

<asp:requiredfieldvalidator id="req1" runat="server" controltovalidate="txtName"
errormessage="Required!" display="Dynamic"></asp:requiredfieldvalidator>

Mobile number validation

<asp:regularexpressionvalidator id="RegularExpressionValidator3" runat="server"
errormessage="Enter valid mobile no!" validationexpression="^(\+\d{1,3}[- ]?)?\d{10}$"
controltovalidate="txtContactNo" display="Dynamic"> </asp:regularexpressionvalidator>

Email validation

<asp:regularexpressionvalidator id="reguler" runat="server" controltovalidate="txtEmail" 
validationexpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
errormessage="Invalid Email Id" display="Dynamic"></asp:regularexpressionvalidator>

Date validation. dd/MM/yyyy format.

<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server" 
display="Dynamic" errormessage="dd/mm/yyyy format only!" controltovalidate="txtFrom"
validationexpression="^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$">
</asp:regularexpressionvalidator>

Name in english:

<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator4" 
ControlToValidate="txtName" ValidationExpression="^[A-Za-z\s]{1,}[\.]{0,1}[A-Za-z\s]{0,}$"
ErrorMessage="Please enter only alphabets and dot!" Display="Dynamic" />

IFSC code validation:

<asp:RegularExpressionValidator ID="regExp1" runat="server" ControlToValidate="txtIFSC"
Display="Dynamic" ErrorMessage="Enter 11 digit correct IFSC Code"
ValidationExpression="^[A-Za-z]{4}[a-zA-Z0-9]{7}$"></asp:RegularExpressionValidator>

Tutorials