a question about the module.
| Project: | CCK Validation |
| Version: | 5.x-0.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
I am trying to build a form to take information from user.
I need to have a field to take the Identify Card Number.
the function to validate the spanish the ICN is:
function valida_nif_cif_nie($cif) {
//returns: 1 = NIF ok, 2 = CIF ok, 3 = NIE ok, -1 = NIF bad, -2 = CIF bad, -3 = NIE bad, 0 = ??? bad
//función creada por David Vidal Serra, Copyleft 2005
$cif=strtoupper($cif);
if (!ereg('((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)',$cif)) {return 0;}
for ($i=0;$i<9;$i++) {$num[$i]=substr($cif,$i,1);}
$suma=$num[2]+$num[4]+$num[6];
for ($i=1;$i<8;$i+=2) {$suma+=substr((2*$num[$i]),0,1)+substr((2*$num[$i]),1,1);}
$n=10-substr($suma,strlen($suma)-1,1);
if (ereg('^[ABCDEFGHNPQS]{1}',$cif)) {
if ($num[8]==chr(64+$n) || $num[8]==substr($n,strlen($n)-1,1)){return 2;} else {return -2;}}
if (ereg('^[KLM]{1}',$cif)) {
if ($num[8]==chr(64+$n)) {return 2;} else {return -2;}}
if (ereg('^[TX]{1}',$cif)) {
if ($num[8]==substr('TRWAGMYFPDXBNJZSQVHLCKE',substr(ereg_replace('X','0',$cif),0,8)%23,1) || ereg('^[T]{1}[A-Z0-9]{8}$',$cif)) {return 3;} else {return -3;}}
if (ereg('(^[0-9]{8}[A-Z]{1}$)',$cif)) {
if ($num[8]==substr('TRWAGMYFPDXBNJZSQVHLCKE',substr($cif,0,8)%23,1)) {return 1;} else {return -1;}}
return 0;
}
I don't know it this module can be used to make this validation.
Thanks
Oskar

#1
Sure this module can be used to do that. Simply use your function on the field's content (like $node->field_icn['value']). When the function returns false validation, you have to call form_set_error(...) to show an error message.
Without calling form_set_error, it won't work.
#2
Automatically closed -- issue fixed for two weeks with no activity.