admin管理员组

文章数量:1355529

I have to add Pan no in my website Application but i have to use jquery for validation so that first 5 no. should be alphabet then 4 no. should be numeric and the last Questions should be alphabet.

$('#txtPANNumber').keypress(function (event) { 
var key = event.which; 
var esc = (key == 127 || key == 8 || key == 0 || key == 46); 
//alert(key); 
//var nor = $("#txtPANNumber").mask("aaaaa9999a"); 
var regExp = /[a-zA-z]{5}\d{4}[a-zA-Z]{1}/; 
var txtpan = $(this).val(); 
if (txtpan.length < 10 ) { 
 if( txtpan.match( regExp) ){ 
  //event.preventDefault(); 
 } 
} else { event.preventDefault(); } });

Please provide some solutions

I have to add Pan no in my website Application but i have to use jquery for validation so that first 5 no. should be alphabet then 4 no. should be numeric and the last Questions should be alphabet.

$('#txtPANNumber').keypress(function (event) { 
var key = event.which; 
var esc = (key == 127 || key == 8 || key == 0 || key == 46); 
//alert(key); 
//var nor = $("#txtPANNumber").mask("aaaaa9999a"); 
var regExp = /[a-zA-z]{5}\d{4}[a-zA-Z]{1}/; 
var txtpan = $(this).val(); 
if (txtpan.length < 10 ) { 
 if( txtpan.match( regExp) ){ 
  //event.preventDefault(); 
 } 
} else { event.preventDefault(); } });

Please provide some solutions

Share Improve this question edited Sep 7, 2016 at 7:06 Mudassir Hasan 28.8k21 gold badges103 silver badges134 bronze badges asked Sep 7, 2016 at 6:54 ProgrammerProgrammer 211 gold badge1 silver badge5 bronze badges 1
  • give a sample of pan no – Mudassir Hasan Commented Sep 7, 2016 at 6:55
Add a ment  | 

2 Answers 2

Reset to default 4

This will do

/[a-zA-z]{5}\d{4}[a-zA-Z]{1}/

Check here

Code

$('#txtPANNumber').change(function (event) {     
 var regExp = /[a-zA-z]{5}\d{4}[a-zA-Z]{1}/; 
 var txtpan = $(this).val(); 
 if (txtpan.length == 10 ) { 
  if( txtpan.match(regExp) ){ 
   alert('PAN match found');
  }
  else {
   alert(Not a valid PAN number);
   event.preventDefault(); 
  } 
 } 
 else { 
       alert('Please enter 10 digits for a valid PAN number');
       event.preventDefault(); 
 } 

});

You can use below regex to validate input for PAN.

[A-Z]{5}[0-9]{4}[A-Z]{1}

Function for JS :

function validatePAN(pan){ 
    var regex = /[A-Z]{5}[0-9]{4}[A-Z]{1}$/; 
    return regex.test(pan); 
}

But don't rely only on JS validation, as JS validation can easily disabled from client side. Put a check on server side as well for inputs.

Also you need to change your if condition to something like below :

if(length == 10) 

本文标签: javascriptValidation on textbox using jquery for pan Number formatStack Overflow