Reputation: 134
I am testing the patterns-attribute for input elements and I built a regex that should do the following: for testing if the input is a valid email address. Is it possible to group various regex expressions like I did in HTML5?
I tried to group like this:
pattern="[ ([a-zA-Z0-9+-.]{1,}) ([@]{1}) ([a-zA-Z0-9+-.]{1,}) ([.]{1}) ([a-zA-Z0-9+-.]{1,}) ]{5,254}"
a-z
and A-Z
and 0-9
and +-.
are allowed with a minimum of 1 char.@
.a-z
and A-Z
and 0-9
and +-.
are allowed with a minimum of 1 char..
.a-z
and A-Z
and 0-9
and +-.
are allowed with a minimum of 1 char.Upvotes: 0
Views: 139
Reputation: 174796
The below regex would satisfy all your conditions. You don't need to add space within the pattern,
^(?=.{5,254}$)[a-zA-Z0-9+-.]{1,}@[a-zA-Z0-9+-.]{1,}[.]{1}[a-zA-Z0-9+-.]{1,}
Add a single character in the demo input and you could see the difference.
Upvotes: 1