• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Regular Expression for email containing string in suffix

I need to validate an email based on whether it contains a string of characters after the @. For example, using 'xyz' the following would validate as true: joebloggs@xyz.com, jbs@rf-opr.xyz.ca, juf@frank.xyz. Anything without the string 'xyz' would return as false. I can get this to work partially but it is dealing with multiple dots that confounds me. Any ideas. Thanks
0
deveson
Asked:
deveson
  • 3
  • 2
1 Solution
 
devesonAuthor Commented:
I searched Regexlib before posting this question. I cant see a solution there that addresses my requirement.
0
 
Terry WoodsIT GuruCommented:
Are you wanting to validate that the top level domain extension is valid? If so, then this article solves exactly that problem:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
devesonAuthor Commented:
Blimey, that's a long article. Unfortunately the top domain level can be anything as long as it contains 'xyz', eg xyz-org.uk, xyz.com, xyz.net would all match.

Here's what I'll try:
1) do a basic validation that the string is an email
2) split the string by the @ char
3) simply check the 2nd part of the email contains 'xyz'

That should do it I think
0
 
Terry WoodsIT GuruCommented:
Perhaps you could trying using a regular expression with pattern:
[A-Z0-9._%+-]+@(?=.*xyz)[A-Z0-9.-]+\.[A-Z]{2,4}

Which would allow:
jbs@rf-opr.xyzz.ca
juf@frank.xxyz

Or this one, which which would not allow those (as they have extra characters on either side of the xyz):
[A-Z0-9._%+-]+@(?=.*(?<=[.@])xyz(?=\.|$))[A-Z0-9.-]+\.[A-Z]{2,4}

0
 
Terry WoodsIT GuruCommented:
Note you'll need:
regEx.IgnoreCase = True
for those.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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