i need a regex to validate the email input in the textbox of the form that end users enter.
Printable View
i need a regex to validate the email input in the textbox of the form that end users enter.
You need to learn to start using Google. It can find plenty of solutions so that you don't have to wait upon us to reply.
http://www.google.com/search?hl=en&q...hp&btnG=Search
thanks; i googled it!
i just paste the code here for other lazy developers like me:D
Code:<?php
$email = "[email protected]";
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "Valid email address.";
}
else {
echo "Invalid email address.";
}
?>
the previous post that i did uses POSIX function i investigated more and found that PCRE (Perl Compatible Regular Expression) functions are faster and more popular that POSIX functions, so i post the PCRE code here also as a better solution for whom care to this thread:
Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]Code:<?php
if ($submit) {
$okay = preg_match(
'/^[A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{2,4}$/',
$emailfield
);
if ($okay) {
echo "E-mail is validated";
} else {
echo "E-mail is incorrect";
}
}else {
?>
<form method="POST" action="email.php">
E-mail address: <input type="text" name="emailfield">
<br><input type="submit" name="submit" value="Validate">
</form>
<?php
}
?>