DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Validation NIF

06.28.2010
| 2659 views |
  • submit to reddit
        //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);
	}