Common function to validate IFSC code using Regular Expressions in ASP.Net

Last Reply one year ago By pandeyism

Posted one year ago

VS2010-, Coding -


In my project I use to take IFSC (Bank Code) from users.  I need to take this information on many forms.  I want to validate IFSC with a master table.  So I think a gobal function is best for it.  

I rembemer in classical vb6 we had modules to do this work. 

Pl. guide how to use global function in and if posible pl give an example too. 



You are viewing reply posted by: pandeyism one year ago.
Posted one year ago

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.


    <asp:TextBox runat="server" ID="txtIFSCCode" />
    <asp:Button ID="Button1" Text="Validate" runat="server" OnClick="Validate" />



protected void Validate(object sender, EventArgs e)
    IFSC ifsc = new IFSC();
    bool isValid = ifsc.ValidateIFSCCode(txtIFSCCode.Text.Trim());
    Response.Write(isValid ? "Valid" : "Invalid");


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;