ohdang888 Posted March 1, 2008 Share Posted March 1, 2008 how do i validate an email address?????/... like... make sure there is an @ and a .com, or.net, etc. i tried the code below but it didn;t work. if(!validate_email_address($email)){ Link to comment https://forums.phpfreaks.com/topic/93902-validate-email-address/ Share on other sites More sharing options...
Orio Posted March 1, 2008 Share Posted March 1, 2008 <?php function valid_email($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) return false; return true; } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/93902-validate-email-address/#findComment-481175 Share on other sites More sharing options...
ohdang888 Posted March 1, 2008 Author Share Posted March 1, 2008 How does the return true and return false work??? Link to comment https://forums.phpfreaks.com/topic/93902-validate-email-address/#findComment-481194 Share on other sites More sharing options...
MasterACE14 Posted March 1, 2008 Share Posted March 1, 2008 basically, the return false is at the end of the if. The whole if can be interpretted like this: IF the email IS NOT valid fail the test otherwise pass the test Returning false is just a way of letting the script know whether the test was a success or not. by returning false your letting it know that the email address it NOT valid so you can then echo "your email is not valid"; or whatever. its kinda hard to explain, but I hope you get the idea Regards ACE Link to comment https://forums.phpfreaks.com/topic/93902-validate-email-address/#findComment-481198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.