You must Sign In to post a response.
  • Category: .NET

    How to validate PAN NO. in a text box on textbox lost focus using jquery?

    Validate a pan number of the text I need regular expression validator which will allow the empty textbox and Pan Number validation can you give that regular express validator.
  • #765480

    Please refer below code for this.

    In Html,

    <input type="text" id ="txtPan" onblur="ValidatePAN();"/>

    <span id="errormsg"/>

    In Jquery -


    function ValidatePAN()
    var pan=$("#txtPan").val();
    var regpan = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

    if(regpan.test(pan) == false)
    $("#errormsg").val('Invalid pan number');
    $("#errormsg").val('Valid pan number');

  • #765485
    Hai Srirama,
    As the PAN number is having specific pattern as well as the fixed number for characters, so we can write the RegEx and then validate it with the entered value.
    Below RegEx can be used for the validation:
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #765497
    what my question if it is blank it should not be show for validation message

  • #765498
    PAN card number is a unique national number issued in India for tax related purposes, it does contains a combination of alpha numeric characters
    see below javascript code that contains a regular expression for PAN card validation, see below snippet

    <script type="text/javascript" language="javascript">
    function fnValidatePAN(Obj) {
    if (Obj == null) Obj = window.event.srcElement;
    if (Obj.value != "") {
    ObjVal = Obj.value;
    var panPat = /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/;
    var code = /([C,P,H,F,A,T,B,L,J,G])/;
    var code_chk = ObjVal.substring(3,4);
    if ( == -1) {
    alert("Invalid Pan No");
    return false;
    if (code.test(code_chk) == false) {
    alert("Invaild PAN Card No.");
    return false;

    you can call this javascript method on Textbox blur event

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765505
    I need a custom regular expression validator which also allow null value when nothing entered in the textbox

  • #765544
    Hi Srirama,

    Validators by convention don't validate empty text. If you want to require a value, you have to also add a RequiredFieldValidator.

    MSDN says

    Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.

    So per MSDN comments, it should work as expected

  • Sign In to post your comments