Over a million developers have joined DZone.

Validation NIF

·
//Valida nif, teoria do numeros adaptado a realidade PT


	public  function validatedNIF($value){
		if(!$value)
			return false;
		$a = str_split($value);
		$a[8]=(int)$a[8];//humm
		$validatedValue = $a[0]*9+$a[1]*8+$a[2]*7+$a[3]*6+$a[4]*5+$a[5]*4+$a[6]*3+$a[7]*2;
		return (0===$a[8])? !( (bool)($validatedValue % 11) ||(bool)(($validatedValue+10)% 11) ) : !((bool)($validatedValue+$a[8])%11);
	}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}