I have to make a patientsform (made in HTML) and ask a few personal questions. For example: a patient number. I have used an input field where someone can type their number. The number has to be exactly 8 numbers. If this is true, the input field has to turn green, if not, it needs to give an alert and turn the input field red. This is the code I have so far:
function checkpnummer() {
if(!$('#patientnummer').val().match(/^\d{8}$/)) {
$('#patientnummer').css({"background-color": "#CD5C5C"});
alert("Vul een patientnummer in dat bestaat uit 8 cijfers.");
}
else {
$("#patientnummer").css("background-color", "#00FA9A");
$("#patientnummer").focusout();
}
}
}
However, If I try to fill in a number in my inputfield (in HTML) it does not make a difference between a correct or an incorrect input. Could someone help me solve my problem?