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:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}