function is_valid_email($email) {
$result = FALSE;
// # is the delimiter, the i after last # is a switch denoting upper/lower case
if(preg_match("#^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$#i", $email)) {
$result = TRUE;
}
return $result;
}
IF your regex is ok (none of this is tested btw) you’d use it like this:
Well I don’t know what the rest of your page is doing and I dont know what your form contains exactly.
Temporarily tell your form to submit to this test page (ie set <form action=“testpage.php” method="“POST”>)
testpage.php
<?php
var_dump($_POST['Email']);
echo '<hr />';
function is_valid_email($email) {
$result = FALSE;
if(preg_match("#^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$#i", $email)) {
$result = TRUE;
}
return $result;
}
if ($_POST["Email"] =="" || is_valid_email($_POST["Email"] ) ) {
echo 'Sending you to Location: index.html';
} else {
echo 'Showing you the form.... ';
}
Show us the output of that page when Email is not filled in, when its filled in with a non-email “asdfasdf” and when its got a valid email “asdf@asdf.com”.
Sorry but I’m not in a position to test any of this, just guessing at the code, which is not ideal …
if ($_POST["Email"] =="" || !(is_valid_email($_POST['Email']) ) ) {
echo 'Showing you the form.... ';
} else {
echo 'Sending you to Location: index.html';
}