1: <?php
2:
3: /**
4: * Pry Framework
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file LICENSE.txt.
10: *
11: */
12:
13: namespace Pry\Validate\Validator;
14:
15: use Pry\Validate\ValidateAbstract;
16:
17: /**
18: * Validateur Alphanuméric
19: *
20: * @category Pry
21: * @package Validate
22: * @subpackage Validate_Validator
23: * @version 1.0.0
24: * @author Olivier ROGER <oroger.fr>
25: */
26: class Alnum extends ValidateAbstract
27: {
28:
29: /**
30: * Constructeur. Par défaut autorise les espaces
31: *
32: * @param boolean $espace Autorise ou non les espaces dans les chaines
33: * @access public
34: */
35: public function __construct($espace = true)
36: {
37: $this->espace = (boolean) $espace;
38: $this->errorMsg = "n'est pas une valeur alphanumérique";
39: }
40:
41: /**
42: * Vérifie si $string est alphanumérique
43: *
44: * @param string $string
45: * @return boolean
46: */
47: public function isValid($string)
48: {
49: $string = $this->cleanString($string);
50: //On cherche si on ne trouve pas d alnum. Donc si true = la chaine n'est pas alnum on renvoi false.
51: if ($this->espace)
52: if (preg_match('/[^a-zA-Z0-9\s\-]/', $string))
53: return false;
54: else
55: return true;
56: else
57: if (preg_match('/[^a-zA-Z0-9\-]/', $string))
58: return false;
59: else
60: return true;
61: }
62:
63: }