Solved

Regex not recognising correct emails

Posted on 2011-02-11
8
398 Views
Last Modified: 2012-05-11
I am trying to use RegEx to check email address's and do an action when they dont match

I have tried the code below but this seems to not match everything, i have tested this by removing the extention from the end of an email and a normal .co.uk extention on a second email both emails fail the test..

Can anyone help with this please
Set RegularExpressionObject = New RegExp

		With RegularExpressionObject
		.Pattern = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
		.IgnoreCase = True
		.Global = True
		End With

		Set expressionmatch = RegularExpressionObject.Execute(" & Me.Recipient & ")

		If expressionmatch.Count = 0 Then

Open in new window

0
Comment
Question by:QuinnDester
8 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
Comment Utility
Please try this 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]$"
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Can you provide sample of addresses which do not match?
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
One example of a valid email address that does not match is
fred&barney@stonehenge.com
0
 
LVL 3

Author Comment

by:QuinnDester
Comment Utility
I have fixed this thanks the regex does match where it should it wasnt working because i used " & &" to include the variable (Silly Mistake)

but when we have an account closed we add .clossed to the end of the email address, how do i add to the regex to exclude any address that ends in .closed

Thanks
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:QuinnDester
Comment Utility
@ozo:

Yes, there will be many it doesnt match... but then the standards set down for emails include so many different chars, our site is aimed at UK users so standard matching is enough, and this regex is just to filter out who the email is sent to, it wont stop people using the site or signing up, so i am not to fussy about how precise it is..
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
@ozo

I'm beginning to think you have a key on your keyboard bound to the string "fred&barney@stonehenge.com" for questions like these   = )


>>  how do i add to the regex to exclude any address that ends in .closed

Try this mod out:
.Pattern = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}(?!\.closed)(?!\.[A-Z0-9.-]+)\b"

Open in new window

0
 
LVL 3

Author Comment

by:QuinnDester
Comment Utility
works perfectly... thank you
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
NP. Glad to help  : )
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

728 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