Hi akhter,
Refer below example.
HTML
<asp:TextBox runat="server" ID="txtUser" />
<asp:Button Text="Validate" runat="server" OnClick="OnValidate" />
<br />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red" />
Code
C#
protected void OnValidate(object sender, EventArgs e)
{
lblMessage.Text = "";
string userName = txtUser.Text.Trim();
string number = new String(userName.Where(Char.IsDigit).ToArray());
string alphabel = new String(userName.Where(Char.IsLetter).ToArray());
if (number.Length > 4 || alphabel.Length > 4)
{
lblMessage.Text = "Four alphabet and four Digits allowed.";
}
}
VB.Net
Protected Sub OnValidate(ByVal sender As Object, ByVal e As EventArgs)
lblMessage.Text = ""
Dim userName As String = txtUser.Text.Trim()
Dim number As String = New String(userName.Where(Function(x As Char) Char.IsDigit(x)).ToArray)
Dim alphabel As String = New String(userName.Where(Function(x As Char) Char.IsLetter(x)).ToArray)
If number.Length > 4 OrElse alphabel.Length > 4 Then
lblMessage.Text = "Four alphabet and four Digits allowed."
End If
End Sub
Screenshot