Skip to content
elcapo edited this page Oct 16, 2014 · 5 revisions

getNIFCheckDigit obtains and returns the corresponding check digit for a given string. In order to work, the string must match the NIF pattern.

This function has been written to be used from isValidNIF as a helper, but it can still be calle directly.

Usage

/* MySQL */
SELECT getNIFCheckDigit( '335764280' ); /* Returns 'Q' */
SELECT getNIFCheckDigit( '1A1A1A1A' ); /* Returns '' */
/* JavaScript */
var digit = getNIFCheckDigit( '335764280' ); /* digit = 'Q' */
var digit = getNIFCheckDigit( '1A1A1A1A' ); /* digit = '' */
/* PHP */
$digit = getNIFCheckDigit( '335764280' ); /* $digit = 'Q' */
$digit = getNIFCheckDigit( '1A1A1A1A' ); /* $digit = '' */

Return values

[char] - If the string does math the NIF pattern, returns the corresponding check digit. [empty] - If the string doesn't math the NIF pattern, returns an empty string.

Dependencies

In order to verify the format of the string received as parameter, this function uses isValidNIFFormat.

Category

This function is part of the NIF, NIE & CIF package.

SEPA validations

  • [International Bank Account Numbers (IBAN)](International Bank Account Numbers (IBAN))

Spanish validations

Helpers

  • [Common functions](Common functions)
Clone this wiki locally