Email validation to accept apostrophe

Hi all, I want to create a regex as to allow emails with apostrophe in the user's name. For example, I would like Jack.O' to be accepted as valid. I now have the following regex:  '^[\w-\.+]+@([\w-]+\.)+[\w-]{2,4}$' and everytime I'd like to include the apostrophe as a special character it considers it as part of the regex and presents me with the following error: no viable alternative at input ']' . Please bare in mind I am not very good at creating regex, but as far as I read and documented myself by including \' it should escape this special character but it just considers it as part of the expression quote itself. Hopefully, you guys will understand what I mean.  Could you please help me with some information on this? It would be highly appreciated. Many thanks and kind regards, Razvan
2 answers

Trying to come up with some clever way to validate email adresses is bound to fail. The actual correct regex would be something like four pages long, and that's ignoring the fact that there is no single correct solution.

For instance; your regex will consider completely valid .group email addresses to be invalid.

Just check if there is an @ somewhere in there and leave it at that. If you really must know if an address is valid, you should send a token to it and ask the user to confirm the token.


Hi Razvan,

You need to escape the character (since in mendix ' is used to start/end a string), which can be done by preceding it with another '