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 "." 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 } 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! 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. 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. 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 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
Archived
This topic is now archived and is closed to further replies.