Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

RegExp - "NOT Email"

Posted on 2004-08-27
7
413 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 16

Accepted Solution

by:
Walter Ritzel earned 168 total points
ID: 11915736
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
ID: 11918487
(!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
ID: 12111191
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
ID: 12456254
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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