javascript - Strict validation of text field -
on form there 2 fields days , month.
i want simple validation that. once user enter month , i.e., 12 alllow go next field.
if user enters invalid month should focus again on month field , entered text should selected.
i trying use .focus()
, .select()
jquery function not working
this fiction validation test , can number or label.
here jsfiddle link.
<input type="text" id="days" /> <input type="text" id="month" /> jquery("#days").blur(function(){ if(jquery(this).val() == "12"){ alert("valid"); } else { alert("invalid"); jquery(this).focus().select(); } });
$(function({ $('#days').attr("disabled", true); }); $("#months").blur(function(){ if($(this).val()<1 || $(this).val()>12){ $(this).val() = "error, invalid month"; $(this).css('color', 'red'); $(this).focus(); $('#days').attr("disabled", true); return; } else { $('#days').attr("disabled", false); } } });
Comments
Post a Comment