cangrejero Posted December 3, 2007 Share Posted December 3, 2007 I apologize if this is not the correct forum. Have truly looked elsewhere to no avail. Hope you can help! I need to use regex to validate "email addresses" and "usernames". The "email address" format we use is: "some characters/numbers" followed by "." followed by "some more characters/numbers" followed by "@" followed by "webbong.com". The "characters/numbers" portions must allow for "_" and "-" and the "webbong.com" is mandatory; no other domains will be allowed. The "usernames" format we use is a single word that could contain "characters/numbers", "_" and "-". I've tried to work this out to no avail and feel that I have looked at the issue for so long that I am missing the obvious. I will appreciate any guidance that any of the members provides. Thanks!!! Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 3, 2007 Share Posted December 3, 2007 Arguments abound as to which REGEX works for email validation. My take on it? It doesn't exist! REGEX to check email addresses are just glorified spell checkers!, and that's all... they don't validate anything at all, except to ensure what was entered sort of looks like it could possibly be an actual email address = ) They only way to 'validate' is by sending a challenge email to the person registering, and waiting for them to reply. PhREEEk Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 3, 2007 Share Posted December 3, 2007 Arguments abound as to which REGEX works for email validation. My take on it? It doesn't exist! REGEX to check email addresses are just glorified spell checkers!, and that's all... they don't [ivalidate[/i] anything at all, except to ensure what was entered sort of looks like it could possibly be an actual email address = ) They only way to 'validate' is by sending a challenge email to the person registering, and waiting for them to reply. PhREEEk While it's true that you cannot "validate" an email address through the use of regexp, you can validate the format of the email address presented, and that is what he's after here. So, let's look at a sample pattern match: Email: <?php preg_match('|^[A-Z\d._%+-]+@webbong\.com$|i', $email); ?> Username: <?php preg_match('|^[A-Z\d_-]+$|i', $username); ?> If you want to limit to a specific number of characters in your username (ie, between 6 and 20 characters), just replace the pattern with this instead: |^[A-Z\d_-]{6,20}$|i Good luck! Quote Link to comment Share on other sites More sharing options...
cangrejero Posted December 3, 2007 Author Share Posted December 3, 2007 My thanks to PHP_PhREEEk and obsidian. Hope I can learn enough to return the favor one day. Thanks!!! Quote Link to comment Share on other sites More sharing options...
cangrejero Posted December 4, 2007 Author Share Posted December 4, 2007 OK ... here's the deal. The attached file contains scripts for a login system posted by "jpmaster77" in another forum. It works OK except that it doesn't allow for usernames and email addresses with hyphens "-". I tried to implement obsidian's suggestions above but it keeps giving me an error. I pray that I am not out-of-line by uploading the file to see if someone can look it over and advise what I need to do to allow for hyphnes in the above intances. Any guidance is appreciated. Thanks!! [attachment deleted by admin] Quote Link to comment 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.