I now validate email addresses like so:
[-+.'\w]+@[-.\w]+\.[-.\w]+
Which means that if users accidentally have a trailing or leading space in that address (e.g. when copy/pasting), the expression validates to false.
So I want to allow trailing and leading spaces on the above expression. How can I do so?
Use \s*
at the end and start of your regex. \s*
means white spaces having zero or more occurrence.
Consider the following Regex:
\s*[-+.'\w]+@[-.\w]+\.[-.\w]+\s*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With