Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

email validation

Recommended Posts

I need to validate an email to a specific format, but it has to be something that is 100% accurate.  I have to get something that has
something@something.upenn.edu
I have to be able to check for the ".upenn.edu" on the email address
and return an error if it doesn't match, does anyone have any ideas.

Share this post


Link to post
Share on other sites
See [url=http://www.phpfreaks.com/forums/index.php/topic,96280.msg390286.html#msg390286]this[/url] topic and the references in my signature. If you have trouble, show us your code.

Share this post


Link to post
Share on other sites
[code]if (!eregi(.!upenn.edu($email)) {
$errorhandler .= "The email address is invalid for that school";
}[/code]
Is that even close?

Share this post


Link to post
Share on other sites
Please re-read the topic. Use the existing code as-is to match the e-mail, then attempt to customize it.

Share this post


Link to post
Share on other sites
I did it, I actually came up with something, with regular expressions, from using a book, I thought I would never get the hang of regular expressions, and hte best thing is, it actually worked
[code]<?php
if ($yourschool == "UPenn") {
  if (!ereg('\.upenn\.edu', $email)) {
  $errorhandler .= "The email address is not of the proper school format.<br />";
}
}
?>[/code]

Share this post


Link to post
Share on other sites
pretty good, but the only problem is that i could enter ".upenn.edu" as my email address, and it will match your check. you need to make it a bit more rigid. try something like this:
[code]
<?php
if (!preg_match('|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.upenn\.edu$|i', $email)) {
  // invalid email address
}
?>
[/code]

Share this post


Link to post
Share on other sites
If you also want to validate it's an email (so strings like "4895.upenn.edu384" will return false), try this:
[code]<?php
if (strtolower($yourschool) == "upenn") {
  if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+\.upenn\.edu$', $email)) {
  $errorhandler .= "The email address is not of the proper school format.<br />";
}
}
?>[/code]

**Note- Haven't tested it.

Orio.

EDIT- obsidian got me :P

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.