I can't seem to figure out where in my code is wrong, if it is my regex or my code in javascript. When I input the correct email format, the alert is still coming when it is supposed to come out only when the email format is wrong.
I am using the toggleClass functionality of javascript for the alerts in an active modal.
$('.email').blur(function() {
var regex =
/^(([^<>()[\]\\.,;:\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,}))$/;
var isEmailCorrect = $(this).val().match(regex);
$('.modal:visible').find('.popemail').toggleClass('hide', isEmailCorrect);
$('.sub').prop('disabled', !isEmailCorrect);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>Email</label>
<span id="popover-email" class="popemail hide pull-right block-help">
<i class="fa fa-info-circle text-danger" aria-hidden="true"></i>
Please use the proper format of an email</span>
<input type="email" class="email form-control" id="email" name="email" placeholder="Email" value="<?php echo $row['email']; ?>">
When an email is placed with proper format there should be no alert to come out, but when wrong format of email is placed then the alert should come out. I used toggle class for the alert, see line #4.
