SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Validating e-mail address
Hybrid View
-
May 27, 2001, 04:23 #1
Validating e-mail address
Hello,
I'm using the following code to validate an e-mail address:
Code:if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)|(\|)",$email) or !eregi("^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$",$email)) { ....... }
Can anyone tell me why it does not work?
-
May 27, 2001, 06:36 #2
- Join Date
- May 2001
- Location
- Channel Islands Girth: Footlong
- Posts
- 5,882
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is what I use...
<?php
$submit=1;
function check_email ($str) {
// Returns 1 if a valid email, 0 if not
if (ereg ("^.+@.+\\..+$", $str)) {
return 1;
} else {
return 0;
}
}
if (!check_email ($email)) {
$submit=0;
$email = "Invalid Email address";
}
?>
This checks the email submitted. If it was OK it returns a 1 and allows them to continue. If not, it says Invalid email address and offers a Back button to go and try again - this is the other code needed...
<?php
if ($submit) {
echo("<INPUT TYPE='submit' VALUE='Send Comments'>");
}
echo("<INPUT TYPE='button' VALUE='Go Back' ONCLICK='self.history.back();'>");
?>
Hope this helps...
Bookmarks