Wolphie Posted November 17, 2007 Share Posted November 17, 2007 Does anybody know how to check e-mails using regex. E.g. i have a text box where somebody inputs an e-mail address. And if it doesn't contain certain e-mail address formats then return an error message. Characters such as "@" or "." Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/ Share on other sites More sharing options...
rarebit Posted November 17, 2007 Share Posted November 17, 2007 Here's a builtin way: if (filter_var($email, FILTER_VALIDATE_EMAIL)) // builtin php func! and here's a regex way I use (it may need ammendment still, but it also catches one's the other doesn't): function scheck_email($email) { if(!eregi("[A-Z0-9._%-]+@[A-Z0-9.-]{2}([A-Z0-9.-])?\.[A-Z]{2,4}",$email)) return -1; // invalid return 1; // valid } Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/#findComment-393564 Share on other sites More sharing options...
Wolphie Posted November 17, 2007 Author Share Posted November 17, 2007 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/#findComment-393567 Share on other sites More sharing options...
Wolphie Posted November 17, 2007 Author Share Posted November 17, 2007 Hmm, this works on my local server but not on my web server. The built-in function i mean. Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/#findComment-393574 Share on other sites More sharing options...
rarebit Posted November 17, 2007 Share Posted November 17, 2007 http://uk3.php.net/manual/en/function.require.php Warning Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled. Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/#findComment-393576 Share on other sites More sharing options...
Wolphie Posted November 17, 2007 Author Share Posted November 17, 2007 My web server is unix Quote Link to comment https://forums.phpfreaks.com/topic/77750-solved-checking-valid-e-mails-using-regex/#findComment-393577 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.