Jump to content

regex


cangrejero

Recommended Posts

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!!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.