Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Regex not recognising correct emails

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
QuinnDester
Asked:
QuinnDester
1 Solution
 
Easwaran ParamasivamCommented:
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
 
käµfm³d 👽Commented:
Can you provide sample of addresses which do not match?
0
 
ozoCommented:
One example of a valid email address that does not match is
fred&barney@stonehenge.com
0
Technology Partners: 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!

 
QuinnDesterAuthor Commented:
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
 
QuinnDesterAuthor Commented:
@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
 
käµfm³d 👽Commented:
@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
 
QuinnDesterAuthor Commented:
works perfectly... thank you
0
 
käµfm³d 👽Commented:
NP. Glad to help  : )
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now