Solved

RegExp - "NOT Email"

Posted on 2004-08-27
7
404 Views
Last Modified: 2008-03-06
Hi, experts, and thanks for your attention!

I'm a php developer and i badly need to create RegExp evaluating "NOT E-mail", so when i compare string which is not email preg_match will give me "true".

For some reasons i can't just revert preg_match results, because there is a routine which process many patterns and strings and works as described.

By correct E-mail i mean something like *@*.*

Thanks in advance.
0
Comment
Question by:Zmey2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
Walter Ritzel earned 168 total points
Comment Utility
I dont know this kind of regexp validation, just regexps that validates if a email type is a valid one, like this expression:
^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$

And in my code, i test if a email is invalid by false return.

Regards,

Walter.
0
 
LVL 18

Assisted Solution

by:arantius
arantius earned 166 total points
Comment Utility
(!preg_match("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$", $variable))
0
 

Assisted Solution

by:algid
algid earned 166 total points
Comment Utility
pattern:
/^(?!([a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$))/

code snippet:
preg_match('/^(?!([a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$))/', $string)
0
 

Expert Comment

by:algid
Comment Utility
wpcortes and arantius gives regexp which checks whether given string IS EMAIL and then inverses the result. Asker clearly stated it's not what he needs. He needs regexp NOT E-MAIL. Only my solution is valid in this case.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now