I need a regular expression to validate the Spanish passport code with jQuery.
This is my function.
$.validator.addMethod('pasaporte', function(value,element){
return this.optional(element) || /^[a-zA-Z0-9]{5,10}$/.test(value);
});
I need the patterns that the passport code follows as well as the type of DNI format of Spain.
For example.
AAA123456A
The Spanish passport is:
The regex would be:
and your code:
Spanish IDs can be:
1 - One of the following: TRWAGMYFPDXBNJZSQVHLCKE
2 - One of the following: XYZ
So your regex has to be a double check:
But that is to check the format.
Besides, if you want to be more rigorous, there is a formula to know if the number is valid.
The number is divided by
23
and if the rest matches the position of the letter of the document in the listTRWAGMYFPDXBNJZSQVHLCKE
then it is valid.Ex:
12345678z
it is valid. Why?Staying all:
Example of ID and Passport verification :