Checking part of the mail suffix

I am checking for email addresses that might look something like this:

foo@bar.xx.com

      

but also

foo@bar.yy.com

      

I would like to check if it is present xx

or not. The first thing that came to mind was String.Contains

, but it would clearly match occurrences xx

in the string.

Is regexp the way to go? If so, please help me with the template.

Update: mail can have any ending, eg. .com

, .ru

etc.

+3


source to share


3 answers


You can use this regex for testing.

This ensures that @

there is after .xx.

, but can also match the string@.xx.*

.*@[^.]*[.]xx[.]

      



Or this to make sure there is at least one character before and after @

.

.+@[^.]+[.]xx[.]

      

+2


source


There is no easy way to make sure a letter is valid using a regex, look here for more details.

However, for your needs and basic validation, you can use the following regex:



^[^@]+@[^@]+\.(xx|XX).[^@^.]+$

      

+2


source


You can use this pattern: \w+@\w+.xx.\w+

Help: http://regexr.com/

And if you want to check any email, it's best to see this link .

0


source







All Articles