Ninjakreborn Posted September 14, 2006 Share Posted September 14, 2006 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 addressand return an error if it doesn't match, does anyone have any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/ Share on other sites More sharing options...
effigy Posted September 14, 2006 Share Posted September 14, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91734 Share on other sites More sharing options...
Ninjakreborn Posted September 14, 2006 Author Share Posted September 14, 2006 [code]if (!eregi(.!upenn.edu($email)) {$errorhandler .= "The email address is invalid for that school";}[/code]Is that even close? Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91760 Share on other sites More sharing options...
effigy Posted September 14, 2006 Share Posted September 14, 2006 Please re-read the topic. Use the existing code as-is to match the e-mail, then attempt to customize it. Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91782 Share on other sites More sharing options...
Ninjakreborn Posted September 14, 2006 Author Share Posted September 14, 2006 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]<?phpif ($yourschool == "UPenn") { if (!ereg('\.upenn\.edu', $email)) { $errorhandler .= "The email address is not of the proper school format.<br />"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91793 Share on other sites More sharing options...
obsidian Posted September 14, 2006 Share Posted September 14, 2006 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]<?phpif (!preg_match('|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.upenn\.edu$|i', $email)) { // invalid email address}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91795 Share on other sites More sharing options...
Orio Posted September 14, 2006 Share Posted September 14, 2006 If you also want to validate it's an email (so strings like "4895.upenn.edu384" will return false), try this:[code]<?phpif (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 Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91797 Share on other sites More sharing options...
Ninjakreborn Posted September 14, 2006 Author Share Posted September 14, 2006 Ah thinks, that will make it alot more secure, thanks for the help, I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/20731-email-validation/#findComment-91821 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.