I have a form that registers and logs in at the same time but will only allow registration by specific domain, what I need it to do is highlight and not console.log and more importantly prevent the form submitting if not valid.
PHP Form
<form action="actions/register-action.php" method="POST">
<input class="domain-first" type="text" name="email" placeholder="Email" autocomplete="off" required >
<input type="password" name="password" placeholder="Password" required>
<input type="submit" name="submit" value="Register & Login" class="submit-form">
</form>
JQuery
$('.submit-form').on('click', function(){
str = $('.domain-first').val();
str = str.split('@').slice(1);
var allowedDomains = [ 'domain1.co.uk', 'domain2.co.uk' ];
if ($.inArray(str[0], allowedDomains) !== -1) {
alert(str + ' is allowed');
}else{
alert('not allowed');
}
});