PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey guys,
I am using a Regular Expression to weed out bad email addresses. Now I know it isn't foolproof but for some reason it is blocking any hyphen in the first part of them email but not the domain part. For example test-this@test.com will not work but test@this-test.com will work. Here is my expression:
Why is the hyphen in the first part preceded by a backslash? I don't think that one should be there.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
The Hyphen is a special character, so in order to match a hyphen you need to use a backslash. A backslash is needed to make any special character a normal character.
I don't believe the hyphen is a special character. If you remove the backslash in front of it, the regex should work.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Thanks for helping out but it is a special character. I did although try to take it out and that caused a warning and still didn't work. The weird part about it is you can use a hyphen in the domain part of the email address and I used \- to make it work. But the same exact code in the email part doesn't work!
if(!preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9- ]+)*(\.[a-z]{2,3})$#i", $emailAddress))
{
//bad email here
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.