I want to validate email address in html form. I have very little knowledge in regex.
Validation is very simple, just to match any_symbols@any_symbols.two_to_eight_symbols
pattern.
Here is the regex I'm trying to use ^.+@.+\..{2,8}$
. Yet it doesn't work, it validates pattern any_symbols@four_symbols
.
Note: do not worry about such simple validation, on server side I'm doing filter_var
(php) and sending token to that email. Just need to enable button on form when inputed email address fits some sane pattern :)
EDIT Those patterns "any_symbols..." I've mentioned in question are just textual representation of what I'm trying to input. This is not what I type in input field :) Usually I type "test@test.com", or "blabla@hehe.haha" and etc. :)
EDIT2 Actuall code:
var email_regex = new RegExp("^.+@.+\..{2,8}$");
if ($target.val().match(email_regex) !== null){
$button.removeAttr('disabled').removeClass('disabled');
}
else{
$button.attr('disabled', 'disabled').addClass('disabled');
}
EDIT3 *Found the problem!* It wasn't the regex itself, it was how I passed regex to Regex function... it should be
new RegExp(/^.+@.+\..{2,8}$/);
not the
new RegExp("^.+@.+\..{2,8}$");
As I've said this whole regex thing is quite new to me :))