I want to use regex patterns in the answers provided to this question How to validate an email address in JavaScript?
but all of them show red squiggly line unde at sign @
. What's the reason and how to solve this problem?
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
This is my js function:
<!--language: lang-js-->
$('input.filled-in').change(function () {
check_bname(this, $(this).next().next().children().first());
})
function check_bname(input, errorMsg) {
var patternEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
$elemInput = $(input),
$elemError = errorMsg,
$inputVal = $(input).val(),
attrName = $elemInput.attr("id");
if($elemInput.hasClass("filled-in"))
{
patternMatch = $inputVal !==''&& patternEmail.test($inputVal);
}
$elemError[patternMatch ? 'hide' : 'show']();
}
if (!patternMatch) {
if($elemInput.hasClass("filled-in"))
{
$elemError.html($inputVal === '' ? "Should not be empty" : "Use valid form of Email Address e.g (example@example.com)");
}
}