Jump to content

email validation


Ninjakreborn

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
[email protected]
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.
Link to comment
https://forums.phpfreaks.com/topic/20731-email-validation/
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]
Link to comment
https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91793
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]
Link to comment
https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91795
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
Link to comment
https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91797
Share on other sites

Archived

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

×
×
  • Create New...

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.