1 <?php
2 /**
3 * EmailInput.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk;
10
11 /**
12 * This class describes email inputs behavior
13 *
14 * @package Form\Input
15 */
16 class EmailInput extends TextInput{
17
18 /**
19 * Constructor
20 *
21 * @param array $param The input parameters
22 */
23 public function __construct($param){
24 parent::__construct($param);
25 $this->pattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-z]{2,4}$/";
26 }
27
28
29 /**
30 * Check the format of the submitted value
31 *
32 * @param Form $form The form the input is associated with
33 *
34 * @return boolean true if the submitted value is a correct email, else false
35 */
36 public function check(&$form = null){
37 if(parent::check($form)) {
38 if(!empty($this->compare) && $form) {
39 if(($form->getData($this->compare) != $this->value)) {
40 $form->error($this->errorAt, Lang::get("form.email-comparison"));
41 return false;
42 }
43 }
44 return true;
45 }
46 else
47 return false;
48 }
49 }
50