[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php"); 4 5 define( "ERROR_RULE_EMAIL_FORMAT_WRONG", "error_rule_email_format_wrong"); 6 7 /** 8 * \ingroup Validator_Rules 9 * 10 * Given an email address, returns true if it looks like a valid email address (if it has the 11 * valid format) If not, it will return ERROR_RULE_EMAIL_FORMAT_WRONG 12 */ 13 class EmailFormatRule extends Rule 14 { 15 16 var $_email; 17 18 /** 19 * The constructor does nothing. 20 */ 21 function EmailFormatRule() 22 { 23 $this->Rule(); 24 } 25 26 /** 27 * Validates the format of the given email address 28 * Based on PEAR Validate (http://pear.php.net/package/Validate) 29 * 30 * @param value The email address whose format we are going to validate 31 * @return True if the address is a valid one or false otherwise 32 */ 33 function validate($value) 34 { 35 // the base regexp for address 36 // I get these code from PEAR::Validate v0.64 37 $regex = '&^(?: # recipient: 38 ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")| #1 quoted name 39 ([-\w!\#\$%\&\'*+~/^`|{}]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}]+)*)) #2 OR dot-atom 40 @(((\[)? #3 domain, 4 as IPv4, 5 optionally bracketed 41 (?:(?:(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:[0-1]?[0-9]?[0-9]))\.){3} 42 (?:(?:25[0-5])|(?:2[0-4][0-9])|(?:[0-1]?[0-9]?[0-9]))))(?(5)\])| 43 ((?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)*[a-z0-9](?:[-a-z0-9]*[a-z0-9])?) #6 domain as hostname 44 \.((?:([^-])[-a-z]*[-a-z])?)) #7 ICANN domain names 45 $&xi'; 46 47 if( preg_match($regex, $value) ){ 48 $this->_setError(false); 49 return true; 50 } else { 51 $this->_setError(ERROR_RULE_EMAIL_FORMAT_WRONG); 52 return false; 53 } 54 } 55 } 56 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |