简体   繁体   中英

How to Validate Pan Card Number Format Using Jquery Client Side Or C# Server side

I have to add Pan Card Number in my Application. so that The format is like Ex:BNOPS0157F first 5 no. should be alphabet then 4 no. should be numeric and the last is alphabet. How Can do that

use RegularExpressionValidator to achieve try this...

<asp:RegularExpressionValidator Display="Dynamic" ControlToValidate="txtPan"
   ID="regConVal" ValidationExpression="^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$" runat="server" ErrorMessage="PAN Number Should be this format 'XXXXX0000X'."
   ForeColor="#ff0000" ValidationGroup="ConVal"></asp:RegularExpressionValidator>

in javascript

 var pan = "ABCDE1234F"; var pan2 = "ASW4578W32" var patt =/^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$/; console.log(patt.test(pan)); console.log(patt.test(pan2)); 

or in c#

using System.Text.RegularExpressions;

string checkPanNo = @"^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$";
bool isPANValid = Regex.IsMatch(txtPanNo.Text.ToString().Trim(), checkPanNo);
if (isPANValid == true)
{
     //valid pan number
}
else 
{
    //invalid pan number
}
//Use below jQuery for PAN Validation.

$(".txtPANID").keypress(function (e) {
        var textValue = $(this).val().toUpperCase();
        var char = String.fromCharCode(e.which)
        console.log(textValue + char);
        var regexp = /^([A-Z]([A-Z]([A-Z]([A-Z]([A-Z]([0-9]([0-9]([0-9]([0-9]([A-Z])?)?)?)?)?)?)?)?)?)?$/;
        if (!regexp.test(textValue + char))
            e.preventDefault();
        //return false
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM