I am doing a program which you need to put the Spanish document (NIF, NIE, CIF) and I need to check that the data entered are correct.
The user enters the value in a single input and must match the NIF, or NIE, or CIF format.
This is the code I have so far:
if (document.formProveedor.NIF.value!="") {
var regNIF = /^([0-9]){8}([A-Z]){1}$/;
var regNIE = /^([A-Z]){1}([0-9]){7}([A-Z]){1}$/;
var regCIF = /^([A-Z]){1}([0-9]){8}}$/;
if(regNIF.test(document.formProveedor.NIF.value) == false) {
alert("El NIF introducido no es correcto.");
document.formProveedor.NIF.focus();
return false;
}else if(regNIE.test(document.formProveedor.NIF.value) == false){
alert("El NIE introducido no es correcto.");
document.formProveedor.NIF.focus();
return false;
}else if(regCIF.test(document.formProveedor.NIF.value) == false){
alert("El CIF introducido no es correcto.");
document.formProveedor.NIF.focus();
return false;
}
}
EXAMPLES:
NIF: 74063793K
NIE: Y9945517D
CIF: G82868043
-
When I fill in the field with a NIF and the function is executed, I skip the alert
"The NIE entered is not correct."
-
When I fill the field with a NIE and the function is executed, I skip the alert
"The NIF entered is not correct."
-
When I fill the field with a CIF and the function is executed, I skip the alert
"The NIF entered is not correct."