Search code examples
asp.netregexunobtrusive-javascript

how can I join two regex into one?


I have two regex that I need to join into one as I am using the RegularExpressionAttribute in ASP.NET and it does not allow multiple instances.

How can I join the following two regex into one?

.*?@(?!.*?\.\.)[^@]+$
[\x00-\x7F]

the first one checks that there are not 2 consecutive dots in the domain part of an email and the second regex checks that all characters are ascii

I thought it might have been as easy as joining them together like (.*?@(?!.*?\.\.)[^@]+$)([\x00-\x7F]) but this does not work

Here is link to previous post relating to this problem

EDIT: I am decorating an string property of my viewmodel using reglarexpression attribute and this gets rendered into javascript using unobtrusive therefore it has to validate using javascript. I failed to mention this in my initial post


Solution

  • You can use:

    ^[\x00-\x7F]+?@(?!.*?\.\.)(?=[\x01-\x7F]+$)[^@]+$