diff options
author | xue <> | 2006-01-16 22:22:39 +0000 |
---|---|---|
committer | xue <> | 2006-01-16 22:22:39 +0000 |
commit | 473e29dfcec480bd146bc31e42f0f9438b7210f9 (patch) | |
tree | 033dfe5c923446ae1178b9af596b274cf067bc13 /framework/Web/UI/WebControls/TEmailAddressValidator.php | |
parent | 318ca1a7cc0085f36a6ca6648b6b2a7eb2bab295 (diff) |
Added validation examples.
Diffstat (limited to 'framework/Web/UI/WebControls/TEmailAddressValidator.php')
-rw-r--r-- | framework/Web/UI/WebControls/TEmailAddressValidator.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/framework/Web/UI/WebControls/TEmailAddressValidator.php b/framework/Web/UI/WebControls/TEmailAddressValidator.php new file mode 100644 index 00000000..48516c44 --- /dev/null +++ b/framework/Web/UI/WebControls/TEmailAddressValidator.php @@ -0,0 +1,60 @@ +<?php
+/**
+ * TEmailAddressValidator class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Using TRegularExpressionValidator class
+ */
+Prado::using('System.Web.UI.WebControls.TRegularExpressionValidator');
+
+/**
+ * TEmailAddressValidator class
+ *
+ * TEmailAddressValidator validates whether the value of an associated
+ * input component is a valid email address. It will check MX record
+ * if checkdnsrr() is implemented.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TEmailAddressValidator extends TRegularExpressionValidator
+{
+ const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
+
+ public function getRegularExpression()
+ {
+ $regex=parent::getRegularExpression();
+ return $regex===''?self::EMAIL_REGEXP:$regex;
+ }
+
+ public function evaluateIsValid()
+ {
+ $valid=parent::evaluateIsValid();
+ if($valid && function_exists('checkdnsrr'))
+ {
+ if(($value=$this->getValidationValue($this->getValidationTarget()))!=='')
+ {
+ if(($pos=strpos($value,'@'))!==false)
+ {
+ $domain=substr($value,$pos+1);
+ return $domain===''?false:checkdnsrr($domain,'MX');
+ }
+ else
+ return false;
+ }
+ }
+ return $valid;
+ }
+}
+
+?>
\ No newline at end of file |