Solved

Regex not recognising correct emails

Posted on 2011-02-11
8
427 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
[X]
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
8 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 34871125
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 75

Expert Comment

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

Expert Comment

by:ozo
ID: 34871327
One example of a valid email address that does not match is
fred&barney@stonehenge.com
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:QuinnDester
ID: 34871376
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
 
LVL 3

Author Comment

by:QuinnDester
ID: 34871428
@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 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34871656
@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
ID: 34871746
works perfectly... thank you
0
 
LVL 75

Expert Comment

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…

630 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