contributions/db.textfields/model/base/fields/dbfield.text.email.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A field to hold an email 00004 * 00005 * Field in DB should be defined as VARCHAR(255) 00006 * 00007 * The theoretical maximum length of an email is 320 characters. 255 characters seem sufficient, though 00008 * 00009 * @since 0.5.1 00010 * 00011 * @author Gerd Riesselmann 00012 * @ingroup TextFields 00013 */ 00014 class DBFieldTextEmail extends DBFieldText { 00015 public function __construct($name, $default_value = null, $policy = self::NOT_NULL) { 00016 parent::__construct($name, 255, $default_value, $policy); 00017 } 00018 00019 /** 00020 * Returns true, if the value passed fits the fields restrictions 00021 * 00022 * @param string $value 00023 * @return Status 00024 */ 00025 public function validate($value) { 00026 $ret = parent::validate($value); 00027 if ($ret->is_ok() && Cast::string($value) !== '') { 00028 if (!Validation::is_email($value)) { 00029 $ret->append(tr( 00030 '%field must be a valid email address', 00031 'textfields', 00032 array( 00033 '%field' => tr($this->get_field_name()), 00034 ) 00035 )); 00036 } 00037 } 00038 return $ret; 00039 } 00040 }