I'm trying to go through some basics of classes and functions and I am attempting to modify an existing function (1st code block below) so that it checks to see if there is any data in the field before performing validation. If it does then validate otherwise exit and return true. My attempt is the 2nd code block.
Code: Select all
function isEmailAddress($field, $msg)
{
$value = $this->_getValue($field);
$pattern = "/^(їa-zA-Z0-9])+(ї\.a-zA-Z0-9_-])*@(їa-zA-Z0-9_-])+(\.їa-zA-Z0-9_-]+)+/";
if(preg_match($pattern, $value))
{
return true;
}
else
{
$this->_errorListї] = array("field" => $field, "value" => $value, "msg" => $msg);
return false;
}
}Code: Select all
// check whether email field has data in or not, if it does then validate
function isEmailOrEmpty($field, $msg)
{
//$value = $this->_getValue($field);
if(!isset($this->_getValueї$field]))
{
$pattern = "/^(їa-zA-Z0-9])+(ї\.a-zA-Z0-9_-])*@(їa-zA-Z0-9_-])+(\.їa-zA-Z0-9_-]+)+/";
if(preg_match($pattern, $value))
{
return true;
}
}
else
{
return true;
}
}Regards
James