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

respectsDocPattern tests a string against a regexp pattern. Actually, this function has been written as a helper for isValidNIFFormat, isValidNIEFormat and isValidCIFFormat, but it can still be called directly.

Usage

/* MySQL */
SELECT respectsDocPattern( '33576428Q',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 1 */
SELECT respectsDocPattern( '1A1A1A1A',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 0 */
/* JavaScript */
var isValid = respectsDocPattern( '33576428Q',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 1 */
var isValid = respectsDocPattern( '1A1A1A1A',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 0 */
/* PHP */
$isValid = respectsDocPattern( '33576428Q',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 1 */
$isValid = respectsDocPattern( '1A1A1A1A',
    '[KLM0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][A-Z]' ); /* Returns 0 */

Return values

  • 1 - If the string fits the pattern.
  • 0 - Otherwise.

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