Regular expression for validate Mobile number using RegularExpressionValidator in ASP.Net

Last Reply on Jul 14, 2017 06:08 AM By dharmendr

Posted on Jul 14, 2017 05:24 AM

can anybody help me regarding regular expreesion for mobile number .that should allow only numbers and should contain 10digits.

 

googled  somany contect but not find exactly.

 

some are giving error when i entered bellow 10 digits.but if i enter 12 digits error is not giving.

You are viewing reply posted by: dharmendr on Jul 14, 2017 06:08 AM.
Posted on Jul 14, 2017 06:08 AM

Hi Mahesh1986,

Refer the below sample.

HTML

<asp:TextBox runat="server" ID="txtMobileNumber" />
<br />
<asp:RequiredFieldValidator ID="rfvMobNo" runat="server" ErrorMessage="Required"
    Display="Dynamic" ValidationGroup="Validate" ForeColor="Red" ControlToValidate="txtMobileNumber"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revMobNo" runat="server" ErrorMessage="Invalid Mobile Number."
    ValidationExpression="^([0-9]{10})$" ControlToValidate="txtMobileNumber" ValidationGroup="Validate"
    ForeColor="Red" Display="Dynamic"></asp:RegularExpressionValidator>
<br />
<asp:Button Text="Submit" runat="server" OnClick="Submit" ValidationGroup="Validate" />

Screenshot