This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
No length validation #4
Open
Description
The functions don't check the identification numbers length. Any valid NIF, NIE with numbers added before is validated as correct. Example:
11111111H is a valid NIF 911111111H is not valid but the functions return it as valid, also 8911111111H, 98711111111H, ... While the final string is a valid NIF/NIE any number added in front is ignored by the validator.
The problem comes from the substring function when zeros are added to the number and the string is reduced to 9 characters ignoring the original length.
Fast workarround: Remove the zero adding on the isValidNIF and isValidNIE function. The NIF NIE variable is suposed to be varchar, starting zeros should be there.
/* Remove this conditional block
if( !preg_match( "/^[A-Z]+$/i", substr( $fixedDocNumber, 1, 1 ) ) ) {
$fixedDocNumber = strtoupper( substr( "000000000" . $docNumber, -9 ) );
} else {
$fixedDocNumber = strtoupper( $docNumber );
}
/**/
// Replace with:
$fixedDocNumber = strtoupper( $docNumber );
Metadata
Metadata
Assignees
Labels
No labels