|
-
October 4th, 2008, 04:58 AM
#1
[RESOLVED] REGEX to validate email inputs
i need a regex to validate the email input in the textbox of the form that end users enter.
-
October 4th, 2008, 07:51 AM
#2
Re: REGEX to validate email inputs
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
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 4th, 2008, 09:57 AM
#3
Re: REGEX to validate email inputs
thanks; i googled it!
i just paste the code here for other lazy developers like me
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.";
}
?>
-
October 6th, 2008, 09:31 AM
#4
Re: [RESOLVED] REGEX to validate email inputs
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:
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
}
?>
Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|