1 |
<?php
|
1 |
<?php
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
3 |
// +----------------------------------------------------------------------+
|
3 |
// +----------------------------------------------------------------------+
|
4 |
// | PHP version 4.0 |
|
4 |
// | PHP version 4.0 |
|
5 |
// +----------------------------------------------------------------------+
|
5 |
// +----------------------------------------------------------------------+
|
6 |
// | Copyright (c) 1997-2003 The PHP Group |
|
6 |
// | Copyright (c) 1997-2003 The PHP Group |
|
7 |
// +----------------------------------------------------------------------+
|
7 |
// +----------------------------------------------------------------------+
|
8 |
// | This source file is subject to version 2.0 of the PHP license, |
|
8 |
// | This source file is subject to version 2.0 of the PHP license, |
|
9 |
// | that is bundled with this package in the file LICENSE, and is |
|
9 |
// | that is bundled with this package in the file LICENSE, and is |
|
10 |
// | available at through the world-wide-web at |
|
10 |
// | available at through the world-wide-web at |
|
11 |
// | http://www.php.net/license/2_02.txt. |
|
11 |
// | http://www.php.net/license/2_02.txt. |
|
12 |
// | If you did not receive a copy of the PHP license and are unable to |
|
12 |
// | If you did not receive a copy of the PHP license and are unable to |
|
13 |
// | obtain it through the world-wide-web, please send a note to |
|
13 |
// | obtain it through the world-wide-web, please send a note to |
|
14 |
// | license@php.net so we can mail you a copy immediately. |
|
14 |
// | license@php.net so we can mail you a copy immediately. |
|
15 |
// +----------------------------------------------------------------------+
|
15 |
// +----------------------------------------------------------------------+
|
16 |
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
16 |
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
|
17 |
// +----------------------------------------------------------------------+
|
17 |
// +----------------------------------------------------------------------+
|
18 |
//
|
18 |
//
|
19 |
// $Id: Email.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
|
19 |
// $Id: Email.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
|
20 |
|
20 |
|
21 |
require_once('HTML/QuickForm/Rule.php');
|
21 |
require_once('HTML/QuickForm/Rule.php');
|
22 |
|
22 |
|
23 |
/**
|
23 |
/**
|
24 |
* Email validation rule
|
24 |
* Email validation rule
|
25 |
* @version 1.0
|
25 |
* @version 1.0
|
26 |
*/
|
26 |
*/
|
27 |
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
|
27 |
class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule
|
28 |
{
|
28 |
{
|
29 |
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
|
29 |
var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
|
30 |
|
30 |
|
31 |
/**
|
31 |
/**
|
32 |
* Validates an email address
|
32 |
* Validates an email address
|
33 |
*
|
33 |
*
|
34 |
* @param string $email Email address
|
34 |
* @param string $email Email address
|
35 |
* @param boolean $checkDomain True if dns check should be performed
|
35 |
* @param boolean $checkDomain True if dns check should be performed
|
36 |
* @access public
|
36 |
* @access public
|
37 |
* @return boolean true if email is valid
|
37 |
* @return boolean true if email is valid
|
38 |
*/
|
38 |
*/
|
39 |
function validate($email, $checkDomain = false)
|
39 |
function validate($email, $checkDomain = false)
|
40 |
{
|
40 |
{
|
41 |
if (preg_match($this->regex, $email)) {
|
41 |
if (preg_match($this->regex, $email)) {
|
42 |
if ($checkDomain && function_exists('checkdnsrr')) {
|
42 |
if ($checkDomain && function_exists('checkdnsrr')) {
|
43 |
$tokens = explode('@', $email);
|
43 |
$tokens = explode('@', $email);
|
44 |
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
|
44 |
if (checkdnsrr($tokens[1], 'MX') || checkdnsrr($tokens[1], 'A')) {
|
45 |
return true;
|
45 |
return true;
|
46 |
}
|
46 |
}
|
47 |
return false;
|
47 |
return false;
|
48 |
}
|
48 |
}
|
49 |
return true;
|
49 |
return true;
|
50 |
}
|
50 |
}
|
51 |
return false;
|
51 |
return false;
|
52 |
} // end func validate
|
52 |
} // end func validate
|
53 |
|
53 |
|
54 |
|
54 |
|
55 |
function getValidationScript($options = null)
|
55 |
function getValidationScript($options = null)
|
56 |
{
|
56 |
{
|
57 |
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
57 |
return array(" var regex = " . $this->regex . ";\n", "{jsVar} != '' && !regex.test({jsVar})");
|
58 |
} // end func getValidationScript
|
58 |
} // end func getValidationScript
|
59 |
|
59 |
|
60 |
} // end class HTML_QuickForm_Rule_Email
|
60 |
} // end class HTML_QuickForm_Rule_Email
|
61 |
?>
|
61 |
?>
|