Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regex not recognising correct emails

Posted on 2011-02-11
8
Medium Priority
?
431 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…

722 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