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

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

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

Usage

/* MySQL */
SELECT getCIFCheckDigit( 'H24930830' ); /* Returns '6' */
SELECT getCIFCheckDigit( '1A1A1A1A' ); /* Returns '' */
/* JavaScript */
var digit = getCIFCheckDigit( 'H24930830' ); /* digit = '6' */
var digit = getCIFCheckDigit( '1A1A1A1A' ); /* digit = '' */
/* PHP */
$digit = getCIFCheckDigit( 'H24930830' ); /* $digit = '6' */
$digit = getCIFCheckDigit( '1A1A1A1A' ); /* $digit = '' */

Return values

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

Dependencies

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

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