Created
April 25, 2013 20:13
-
-
Save ruizfrontend/5462765 to your computer and use it in GitHub Desktop.
Jquery Validate spanish DNI (adapted from http://xandrusoft.blogspot.com.es/2009/08/validar-dni-en-un-formulario.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.validator.addMethod("dniCheck", function(value, element) { | |
if(/^([0-9]{8})*[a-zA-Z]+$/.test(value)){ | |
var numero = value.substr(0,value.length-1); | |
var let = value.substr(value.length-1,1).toUpperCase(); | |
numero = numero % 23; | |
var letra='TRWAGMYFPDXBNJZSQVHLCKET'; | |
letra = letra.substring(numero,numero+1); | |
if (letra==let) return true; | |
return false; | |
} | |
return this.optional(element); | |
}, "DNI no válido"); | |
$('FORM').validate({ | |
rules: { | |
'FORMFIELDNAME': { dniCheck: true } | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment