Hi bhushan98,
Create a function that will accept input from user and then validate the input value using RegularExpressions.
Check this example which accepts the below condition.
- Length should be 11
- First 4 characters are alphabets with upper and lower character
- Last seven characters are number
If you want to change the condition then change the RegularExpressions pattern.
HTML
<asp:TextBox runat="server" ID="txtIFSCCode" />
<asp:Button Text="Validate" runat="server" OnClick="Validate" />
Code
C#
protected void Validate(object sender, EventArgs e)
{
bool isValid = ValidateIFSCCode(txtIFSCCode.Text.Trim());
Response.Write(isValid ? "Valid" : "Invalid");
}
public bool ValidateIFSCCode(string ifscCode)
{
System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[A-Za-z]{4}[0-9]{7}$");
return regx.Matches(ifscCode).Count > 0 ? regx.Matches(ifscCode)[0].Success : false;
}
VB.Net
Protected Sub Validate(ByVal sender As Object, ByVal e As EventArgs)
Dim isValid As Boolean = ValidateIFSCCode(txtIFSCCode.Text.Trim())
Response.Write(If(isValid, "Valid", "Invalid"))
End Sub
Public Function ValidateIFSCCode(ByVal ifscCode As String) As Boolean
Dim regx As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("^[A-Za-z]{4}[0-9]{7}$")
Return If(regx.Matches(ifscCode).Count > 0, regx.Matches(ifscCode)(0).Success, False)
End Function
Screenshot