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 Alphabétique.
19: * Accepte également le -
20: * @category Pry
21: * @package Validate
22: * @subpackage Validate_Validator
23: * @version 1.0.0
24: * @author Olivier ROGER <oroger.fr>
25: */
26: class Alpha extends ValidateAbstract
27: {
28:
29: /**
30: * Constructeur. par défaut accepte les espaces
31: *
32: * @param boolean $espace
33: * @access public
34: */
35: public function __construct($espace = true)
36: {
37: $this->espace = (boolean) $espace;
38: $this->errorMsg = "n'est pas une valeur alphabétique";
39: }
40:
41: /**
42: * Vérifie la présence de caractère alphabétique (uniquement)
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 alpha. Donc si true = la chaine n'est pas alpha on renvoi false.
51: if ($this->espace)
52: if (preg_match('/[^a-zA-Z\s\-]/', $string))
53: return false;
54: else
55: return true;
56: else
57: if (preg_match('/[^a-zA-Z\-]/', $string))
58: return false;
59: else
60: return true;
61: }
62:
63: }