In this article I will explain with an example, how to implement US Mobile Number validation using RegularExpressionValidator in ASP.Net.
The Mobile Number entered in the TextBox will be validated using Regular Expression (Regex) and ASP.Net RegularExpressionValidator.
 
 
HTML Markup
The following HTML Markup consists of a TextBox, an ASP.Net RegularExpressionValidator and a Button control.
The RegularExpressionValidator has been set with a Regular Expression for validating Mobile Number in the ValidationExpression property.
The following conditions must satisfy for a US Mobile Number to be termed as valid.
1. It should be 10 digits long.
2. It may begin with an optional (.
3. After the optional (, it must be 3 digits. If it does not have a (, it must start with 3 digits.
4. It can have an optional ) after first 3 digits.
5. It can have an optional hyphen (-) or empty space after ), if present or after first 3 digits.
6. Then there must be 3 more digits.
7. After second set of 3 digits, it can have another optional hyphen (-) or empty space.
8. Finally, it must end with four digits.
Valid examples: (308)-135-7895, 308-135-7895, 308135-7895, 3081357895, (308) 135 7895, 308 135 7895, 308135 7895
Mobile Number:
<asp:TextBox ID="txtMobileNumber" runat="server" />
<asp:RegularExpressionValidator ID="rgxMobileNumber" runat="server" ControlToValidate="txtMobileNumber"
    ValidationExpression="(\([0-9]{3}\)|[0-9]{3})[\s\-]?[\0-9]{3}[\s\-]?[0-9]{4}"
    ErrorMessage="Invalid Mobile Number." ForeColor="Red">
</asp:RegularExpressionValidator>
<hr />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
 
 
Screenshot
US Mobile Number validation using RegularExpressionValidator in ASP.Net
 
 
Demo
 
 
Downloads