I made a function to validate the e-mail address to vaidate and check if they are matched or not.
But it doesn't seem to work because when I var_dump()
.
I got the null
value such as: NULL string(13) 123@gmail.com
. Could you give me some advice to fix this? I'm completely stuck.
function email_validate_n_match($value)
{
if( $value == '') return;
if( preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $value) ) {
static $count = 0;
if($count == 0) {
$value1 = $value;
} else if($count == 1) {
$value2 = $value;
}
var_dump($value2);
// if ($value1 == $value2) {
// return;
// }else{
// $this->clear = false;
// return $this->tag_st . 'Doesn't match.' . $this->tag_ed;
// }
$count++;
return;
} else {
$this->clear = false;
return $this->tag_st . 'Put the correct email address.' . $this->tag_ed;
}
}
EDIT:
Thanks for the answers.
When I put this
static $count = 0;
if($count == 0) {
$value1 = $value;
echo '0';
} else if($count == 1) {
$value2 = $value;
echo '1';
}
it outputs 01
. On the other hand,
If I remove static, I get 00
.
so I think this $count
is working, but I'm still confused why I got NULL
result above.