1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Form Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Form\Rule; |
10
|
|
|
|
11
|
|
|
use Joomla\Form\Rule; |
12
|
|
|
use Joomla\Form\Form; |
13
|
|
|
use Joomla\Registry\Registry; |
14
|
|
|
use SimpleXMLElement; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Form Rule class for the Joomla Framework. |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @deprecated The joomla/form package is deprecated |
21
|
|
|
*/ |
22
|
|
|
class Email extends Rule |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The regular expression to use in testing a form field value. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
* @since 1.0 |
29
|
|
|
* @see http://www.w3.org/TR/html-markup/input.email.html |
30
|
|
|
*/ |
31
|
|
|
protected $regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Method to test the email address and optionally check for uniqueness. |
35
|
|
|
* |
36
|
|
|
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. |
37
|
|
|
* @param mixed $value The form field value to validate. |
38
|
|
|
* @param string $group The field name group control value. This acts as as an array container for the field. |
39
|
|
|
* For example if the field has name="foo" and the group value is set to "bar" then the |
40
|
|
|
* full field name would end up being "bar[foo]". |
41
|
|
|
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form. |
42
|
|
|
* @param Form $form The form object for which the field is being tested. |
43
|
|
|
* |
44
|
|
|
* @return boolean True if the value is valid, false otherwise. |
45
|
|
|
* |
46
|
|
|
* @since 1.0 |
47
|
|
|
*/ |
48
|
|
|
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) |
49
|
|
|
{ |
50
|
|
|
// If the field is empty and not required, the field is valid. |
51
|
|
|
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); |
52
|
|
|
|
53
|
|
|
if (!$required && empty($value)) |
54
|
|
|
{ |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// If the tld attribute is present, change the regular expression to require at least 2 characters for it. |
59
|
|
|
$tld = ((string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required'); |
60
|
|
|
|
61
|
|
|
if ($tld) |
62
|
|
|
{ |
63
|
|
|
$this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])' |
64
|
|
|
. '?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Determine if the multiple attribute is present |
68
|
|
|
$multiple = ((string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple'); |
69
|
|
|
|
70
|
|
|
if ($multiple) |
71
|
|
|
{ |
72
|
|
|
$values = explode(',', $value); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (!$multiple) |
76
|
|
|
{ |
77
|
|
|
// Test the value against the regular expression. |
78
|
|
|
if (!parent::test($element, $value, $group, $input, $form)) |
79
|
|
|
{ |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
else |
84
|
|
|
{ |
85
|
|
|
foreach ($values as $value) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
// Test the value against the regular expression. |
88
|
|
|
if (!parent::test($element, $value, $group, $input, $form)) |
89
|
|
|
{ |
90
|
|
|
return false; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return true; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.