Am trying to validate email address and also if the entered email address match’s the one we don’t want.
the button should remain disabled until everything is fine. and re-enable
But when i try to enter valid email or email which is not equal to [email protected]
the button remains disabled
$(document).ready(function(){
$('.keyup-email').keyup(function() {
var inputVal = $(this).val();
var emailReg = /^(?!.*_)w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})/;
if(!emailReg.test(inputVal)) {
$(".edBtn").prop("disabled", true);
}
else if(inputVal == '[email protected]') {
$(".edBtn").prop("disabled", true);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="keyup-email text-input" name="7" value="">
<div class="row">
<button type="button" id="m1p" class="edBtn">submit</b></button>
2
Answers
Just add else to your conditional statements and make the button disabled to false.
Because you never enable it. Currently your code has two conditions under which you disable the button. Do you want it to be enabled otherwise? Then add that condition:
Basically, if you want the button to be not be disabled, set the
disabled
property tofalse
.