Hi chetan,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox runat="server" ID="txtValue" />
<asp:Button Text="Validate" runat="server" OnClick="ValidateText" />
C#
protected void ValidateText(object sender, EventArgs e)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[0-9]{14}$");
if (regex.IsMatch(txtValue.Text.Trim()))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Valid')", true);
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Invalid')", true);
}
}
VB.Net
Protected Sub ValidateText(ByVal sender As Object, ByVal e As EventArgs)
Dim regex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("^[0-9]{14}$")
If regex.IsMatch(txtValue.Text.Trim()) Then
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "", "alert('Valid')", True)
Else
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "", "alert('Invalid')", True)
End If
End Sub
Screenshot