When asking a user to enter a mobile number, we usually validate if a number has 10 digits or not. If not, we ask user to enter full mobile number. In this case, I've a TextBox control on an ASP.NET Form. The following regular expression in ASPX file validates the number.
.ASPX File
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br\>
- <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
- ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
- ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator>
Here are couple of detailed tutorials in regular expressions with code examples: