Please disable your adblock and script blockers to view this page

RegularExpressionValidator to validate website URL, date format, numbers and decimal in textbox

Introduction: In this article I am going to share the following:
    Validate using RegularExpressionValidator in Asp.Net
  • How to check whether website address valid or not in
  • How to allow only numbers i.e. numeric values or digits in textbox
  • How to allow both number and decimal values in textbox
  • How to validate date format e.g. dd/mm/yyyy in textbox

In previous articles i explained How to Validate textbox, dropdownlist, checkboxlist, radiobuttonlist, listbox, checkbox and radiobutton controls and Jquery to validate email address using regular expression in

Implementation: Let’s create a demo page to demonstrate the validation.

HTML Source Code
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <fieldset style="width:300px;">
                <legend>Validate using RegularExpressionValidator</legend>
                            <asp:TextBox ID="txtWebsite" runat="server" Style="width: 200px" placeholder="e.g."></asp:TextBox><br />
                            <asp:RegularExpressionValidator ID="rgetxtWebsite" runat="server"
                                ControlToValidate="txtWebsite" ErrorMessage="Not a valid website URL" Display="Dynamic" ForeColor="Red" SetFocusOnError="true"
                        <td>Pin Code:</td>
                            <asp:TextBox ID="txtPinCode" runat="server" Style="width: 200px"></asp:TextBox><br />
                            <asp:RegularExpressionValidator ID="rgePinCode" runat="server"
                                ControlToValidate="txtPinCode" SetFocusOnError="True" ForeColor="Red" Display="Dynamic" ErrorMessage="Enter numbers only"
                            <asp:TextBox ID="txtPrice" runat="server" Style="width: 200px"></asp:TextBox><br />
                            <asp:RegularExpressionValidator ID="rgePrice" runat="server"
                                ControlToValidate="txtPrice" SetFocusOnError="True" ForeColor="Red" ErrorMessage="Only numeric or decimal numbers are allowed" Display="Dynamic"
                        <td>Order Date:</td>
                            <asp:TextBox ID="txtOrderDate" placeholder="dd/mm/yyyy" runat="server" Style="width: 200px"></asp:TextBox><br />
                            <asp:RegularExpressionValidator ID="rgeOrderDate" runat="server"
                                ControlToValidate="txtOrderDate" ErrorMessage="Not a valid date format" ForeColor="Red" SetFocusOnError="true" Display="Dynamic"

Now over to you:
"A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates." 
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon