Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Regular Expression for email containing string in suffix

Posted on 2011-10-16
6
Medium Priority
?
162 Views
Last Modified: 2012-06-27
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
Comment
Question by:deveson
  • 3
  • 2
6 Comments
 

Author Comment

by:deveson
ID: 36976840
I searched Regexlib before posting this question. I cant see a solution there that addresses my requirement.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36976851
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
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!

 

Author Comment

by:deveson
ID: 36976866
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
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36976867
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
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 36976872
Note you'll need:
regEx.IgnoreCase = True
for those.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Suggested Courses

577 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