I have this regex jquery:
var regx = /^[\w ._-]+$/;
and
if( $($input).val().match(regx)) {
alert('it works fine');
}
else
{
alert('it does not works fine');
return false
e.preventDefault();
}
Why if I write in input sth like e.j.:
Mary-Michael
I get an alert with it does not works fine, but If I write:
Mary.Michael or Mary_Michael
I get it works fine
I want add – hyphen to regex. Thank you
Hyphens have a special meaning in regex (like
[0-9]) so you should escape it. You ought to escape the period, too, for that matter: