I have been playing around with adding a class to a DOM element when the email value entered into my email form field does not pass my regex test. It will add my message below my field as desired but will do it multiple times, stacking up multiple msg's. The code below does that:
if(emailFault==true){
//error exists
$("#email").addClass("error");
$( "#email" ).after( "<span>" + msgEmail + "</span>" );
//alert(msg);
event.preventDefault();
}
This is some code that I attempted to use but breaks my form completely, but should help give an idea of what I am trying to do:
if(emailFault==true) && (!$("#email").hasClass("error")){
//error exists
$("#email").addClass("error");
$( "#email" ).after( "<span>" + msgEmail + "</span>" );
//alert(msg);
event.preventDefault();
}
Aucun commentaire:
Enregistrer un commentaire