1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core\Kernel\Dtype;
13:
14: use Xoops\Core\Kernel\Dtype;
15: use Xoops\Core\Kernel\XoopsObject;
16:
17: /**
18: * DtypeEmail
19: *
20: * @category Xoops\Core\Kernel\Dtype\DtypeEmail
21: * @package Xoops\Core\Kernel
22: * @author trabis <lusopoemas@gmail.com>
23: * @copyright 2011-2015 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: */
27: class DtypeEmail extends DtypeAbstract
28: {
29: /**
30: * cleanVar prepare variable for persistence
31: *
32: * @param XoopsObject $obj object containing variable
33: * @param string $key name of variable
34: *
35: * @return string
36: */
37: public function cleanVar(XoopsObject $obj, $key)
38: {
39: $value = trim($obj->vars[$key]['value']);
40:
41: if ($obj->vars[$key]['required'] && $value == '') {
42: $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
43: return $value;
44: }
45: if ($value != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $value)) {
46: $obj->setErrors("Invalid Email");
47: return $value;
48: }
49: return $value;
50: }
51: }
52: