Validate_ES
[ class tree: Validate_ES ] [ index: Validate_ES ] [ all elements ]

Source for file ES.php

Documentation is available at ES.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | Copyright (c) 1997-2005 Pierre-Alain Joye,Tomas V.V.Cox              |
  5. // +----------------------------------------------------------------------+
  6. // | This source file is subject to the New BSD license, That is bundled  |
  7. // | with this package in the file LICENSE, and is available through      |
  8. // | the world-wide-web at                                                |
  9. // | http://www.opensource.org/licenses/bsd-license.php                   |
  10. // | If you did not receive a copy of the new BSDlicense and are unable   |
  11. // | to obtain it through the world-wide-web, please send a note to       |
  12. // | pajoye@php.net so we can mail you a copy immediately.                |
  13. // +----------------------------------------------------------------------+
  14. // | Author: Tomas V.V.Cox  <cox@idecnet.com>                             |
  15. // |         Pierre-Alain Joye <pajoye@php.net>                           |
  16. // |         Byron Adams <byron.adams54@gmail.com>
  17. // +----------------------------------------------------------------------+
  18. //
  19. /**
  20.  * Specific validation methods for data used in Spain
  21.  *
  22.  * @category   Validate
  23.  * @package    Validate_ES
  24.  * @author     Tomas V.V.Cox <cox@idecnet.com>
  25.  * @author     Byron Adams <byron.adams54@gmail.com>
  26.  * @copyright  1997-2005 Pierre-Alain Joye,Tomas V.V.Cox
  27.  * @copyright  (c) 2006 Byron Adams
  28.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  29.  * @version    CVS: $Id: ES.php,v 1.13 2006/08/25 08:07:43 badams Exp $
  30.  * @link       http://pear.php.net/package/Validate_ES
  31.  */
  32.  
  33. /**
  34. * Requires base class Validate
  35. */
  36. require_once 'Validate.php';
  37.  
  38. /**
  39.  * Data validation class for Spain
  40.  *
  41.  * This class provides methods to validate:
  42.  *  - Spanish DNI number ("El documento de la identificación nacional")
  43.  *
  44.  * @category   Validate
  45.  * @package    Validate_ES
  46.  * @author     Tomas V.V.Cox <cox@idecnet.com>
  47.  * @author     Byron Adams <byron.adams54@gmail.com>
  48.  * @copyright  1997-2005 Pierre-Alain Joye, Tomas V.V.Cox
  49.  * @copyright  (c) 2006 Byron Adams
  50.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  51.  * @version    Release: @package_version@
  52.  * @link       http://pear.php.net/package/Validate_ES
  53.  */
  54. {
  55.     /**
  56.     * Validate Spanish DNI number ("El documento de la identificación nacional")
  57.     *
  58.     * In Spain, all Spanish citizens are issued with a DNI
  59.     * the numbers are used as identification for almost all purposes.
  60.     * 
  61.     * @param     string    $dni El Documento Nacional de Indentidad a chequear
  62.     * @return    bool      returns true on success false otherwise
  63.     * @author    Tomas V.V.Cox <cox@idecnet.com>
  64.     * @author    Byron Adams <byron.adams54@gmail.com>
  65.     * @link      http://es.wikipedia.org/wiki/Algoritmo_para_obtener_la_letra_del_NIF
  66.     * @link      http://nationalidentificationnumber.quickseek.com/#Spain
  67.     */
  68.     function dni($dni)
  69.     {
  70.         $dni str_replace("-","",trim($dni));
  71.         $letters 'TRWAGMYFPDXBNJZSQVHLCKET';   
  72.        
  73.         $start = (int)(strtoupper($dni{0}== "X");
  74.         
  75.         $number substr($dni,$start,-1);
  76.         $letter strtoupper(substr($dni-1));
  77.         
  78.         if(!ctype_digit($number||
  79.            !ctype_alpha($letter)) {
  80.            return false;
  81.         }
  82.         
  83.         return ($letter == $letters{$number % 23});
  84.     }
  85. }
  86. ?>

Documentation generated on Fri, 05 Jun 2009 08:00:02 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.