I am working on email validation for a login page using jQuery. The problem I am facing is only the else part is getting executed and not if part. Below is the code.
$(document).ready(function () {
$('#my-input').focusout(function () {
emailValidate();
});
function emailValidate() {
var reg = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var email = $('#my-input').val();
if (reg.test('email')) {
console.log('correct');
$('#my-input').css('border', '2px solid green');
$('#span1').css('display', 'none');
} else {
$('#my-input').css('border', '2px solid red');
$('#span1').css('display', 'block');
}
}
});