Ver Mensaje Individual
  #3 (permalink)  
Antiguo 23/03/2011, 02:43
Avatar de masterpuppet
masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 4 meses
Puntos: 845
Respuesta: (Consulta) modificar, ampliar, optimizar validación de formulario

Que tal opzina,

Deberias utilizar PHP 5, osea declarar la visibilidad, podrias ajustar un poco el código(a veces es mejor negar primero) y tambien podrias documentar correctamente, algo asi:

Código PHP:
Ver original
  1. class Validator
  2. {
  3.    /**
  4.     * Variable que almacena errores
  5.     * @var array
  6.     */
  7.     protected $_errors;
  8.    
  9.    /**
  10.     * Este método no evita  Inyecciones SQL
  11.     * Usar con addslashes() (Este es un tema a tratar)
  12.     * @param string $theInput
  13.     * @param string $description
  14.     * @return boolean
  15.     */
  16.     public function validateGeneral($theinput, $description = '')
  17.     {
  18.         if (!trim($theinput)) {
  19.             $this->_errors[] = $description;
  20.             return false;            
  21.         }
  22.         return true;
  23.     }
  24.  
  25.     /**
  26.      * Valida solo texto
  27.      * @param string $theInput
  28.      * @param string $description
  29.      * @return boolean
  30.      */  
  31.     public function validateTextOnly($theinput, $description = '')
  32.     {
  33.         if (!preg_match("/^[A-Za-z0-9-áéíóú\ ]+$/", $theinput)) {
  34.             $this->_errors[] = $description;
  35.             return false;            
  36.         }
  37.         return true;
  38.     }
  39.  
  40.     ...
  41. }

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)