Hi bhushan98,
Create a separate class file and write the code to validate the IFSC code. Then call the method in your required page.
Please take reference to the below code and correct your code.
HTML
<div>
<asp:TextBox runat="server" ID="txtIFSCCode" />
<asp:Button ID="Button1" Text="Validate" runat="server" OnClick="Validate" />
</div>
Code
CS.aspx.cs
protected void Validate(object sender, EventArgs e)
{
IFSC ifsc = new IFSC();
bool isValid = ifsc.ValidateIFSCCode(txtIFSCCode.Text.Trim());
Response.Write(isValid ? "Valid" : "Invalid");
}
IFSC.cs
public class IFSC
{
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;
}
}
Screenshot