This regex is used for validating email addresses, however it doesn’t include the case for apostrophy (‘) which is a valid character in the first part of an email address.
I have tried myself and to use some examples I found, but they don’t work.
^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
How do I modify it slightly to support the ‘ character (apostraphy)?
Per the documentation for an email address, the apostrophe can appear anywhere before the
@symbol, which, in your current regex is:You should be able to add the apostrophe into the brackets of valid characters:
This would make the entire regex:
EDIT (regex contained in single-quotes)
If you’re using this regex inside a string with single-quotes, such as in PHP with
$regex = '^([\w ..., you will need to escape the single-quote in the regex with\':