Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed issue #291.

  • Loading branch information...
commit 4258f11e9ee68e36c044d1e26e035aed0061ba44 1 parent 4caa074
qiang.xue authored
1  CHANGELOG
View
@@ -20,6 +20,7 @@ Version 1.0.5 to be released
- New #247: Added support to allow using Web services in PHP versions lower than 5.2.0 (Qiang)
- New #254: Added support to allow input widgets to be used with tabular inputs (Qiang)
- New #265: Added support to validate time and datetime inputs (Qiang)
+- New #291: Added support to validate emails with name part (Qiang)
- New: Deprecated CHtml::getActiveId() (Qiang)
- New: Added CDbCriteria::mergeWith() (Qiang)
- New: Added Oracle support for Active Record (Ricardo)
3  framework/db/ar/CActiveRecord.php
View
@@ -952,7 +952,8 @@ public function addRelatedRecord($name,$record,$multiple)
$this->_related[$name][]=$record;
}
else if(!isset($this->_related[$name]))
- $this->_related[$name]=$record; }
+ $this->_related[$name]=$record;
+ }
/**
* Returns all column attribute values.
20 framework/validators/CEmailValidator.php
View
@@ -19,10 +19,23 @@
class CEmailValidator extends CValidator
{
/**
- * @var string the regular expression used to validates the attribute value.
+ * @var string the regular expression used to validate the attribute value.
*/
public $pattern='/^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/';
/**
+ * @var string the regular expression used to validate email addresses with the name part.
+ * This property is used only when {@link allowName} is true.
+ * @since 1.0.5
+ * @see allowName
+ */
+ public $fullPattern='/^[^@]*<\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*>$/';
+ /**
+ * @var boolean whether to allow name in the email address (e.g. "Qiang Xue <qiang.xue@gmail.com>"). Defaults to false.
+ * @since 1.0.5
+ * @see fullPattern
+ */
+ public $allowName=false;
+ /**
* @var boolean whether to check the MX record for the email address.
* Defaults to false. To enable it, you need to make sure the PHP function 'checkdnsrr'
* exists in your PHP installation.
@@ -51,8 +64,9 @@ protected function validateAttribute($object,$attribute)
$value=$object->$attribute;
if($this->allowEmpty && ($value===null || $value===''))
return;
- if($valid=preg_match($this->pattern,$value))
- $domain=substr($value,strpos($value,'@')+1);
+ $valid=preg_match($this->pattern,$value) || $this->allowName && preg_match($this->fullPattern,$value);
+ if($valid)
+ $domain=rtrim(substr($value,strpos($value,'@')+1),'>');
if($valid && $this->checkMX && function_exists('checkdnsrr'))
$valid=checkdnsrr($domain,'MX');
if($valid && $this->checkPort && function_exists('fsockopen'))
Please sign in to comment.
Something went wrong with that request. Please try again.