Regular expression allow but don't require leading and trailing whitespace

73 views Asked by At

I have an email form.

I need to allow, but not require, any leading and trailing whitespace.

Right now I have /^\s*[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\s*$/i

The problem with that, is that requires at least one leading and trailing whitespace.

Any ideas?

1

There are 1 answers

0
Philip Devine On BEST ANSWER

You just needed some paren:

^(\s*)[-a-z0-9_+\.]+@([-a-z0-9]+\.)+[a-z0-9]{2,4}(\s*)$