There are many ways to match the expression in textbox:
1) Write Server-side code to match
2) Declare a RegularExpressionValidator for the textbox
3) Use Javascript
1) Server side code:
using System;
using System.Text.RegularExpressions;
void CheckTextBoxValue()
{
string input = TextBox1.text;
Match match = Regex.Match(input, @"^[0-9]{10}$",
RegexOptions.IgnoreCase);
if (match.Success)
{
}
}
2) RegularExpressionValidator: This is an example. Please make your changes accordingly.
<asp:textbox id="TextBox1" runat="server" validationgroup="check" xmlns:asp="#unknown"></asp:textbox>
<asp:regularexpressionvalidator id="RegularExpressionValidator1" runat="server" controltovalidate="TextBox1" xmlns:asp="#unknown">
ErrorMessage="Please Enter Only Numbers" ValidationExpression="^\d+$" ValidationGroup="check"></asp:regularexpressionvalidator>
3) Using Javascript:
function check(){
var re5digit=/^\d{5}$/
if (document.myform.myinput.value.search(re5digit)==-1)
alert("Please enter a valid 5 digit number inside form")
}
<form name="myform">
<input type="text" name="myinput" size=15>
<input type="button" onClick="check()" value="check">
</form>