0

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?

1 Answers1

0

Your first css call doesn't need at all to be an object. Make it just like your second one ($(selector).css("background-color",value)).

N_tonio36
  • 71
  • 4
  • Using `background` changes all the related background CSS property values, not just `background-color`. Using just background is not a good idea. – Rob Sep 17 '17 at 12:41