Jquery验证是否为空、数字或大于13的值

Jquery验证是否为空、数字或大于13的值,jquery,validation,Jquery,Validation,为什么div不会显示,我要做的是检查数值是否不为空,值是否小于13 js css html 错误 谁能帮我改变一下你的状况吗 if(!$.isNumeric(month)){ 到 如果先输入无效数据,然后删除它并重新键入有效数据,则当前实现将无法工作。它不会删除错误消息 您可以这样做: (function($) { if($('#month-holder').length){ $('#month-holder').on("blur", function(e){

为什么div不会显示,我要做的是检查数值是否不为空,值是否小于13

js

css

html


错误
谁能帮我改变一下你的状况吗

  if(!$.isNumeric(month)){

如果先输入无效数据,然后删除它并重新键入有效数据,则当前实现将无法工作。它不会删除错误消息

您可以这样做:

(function($) {     
if($('#month-holder').length){
$('#month-holder').on("blur", function(e){   
    e.preventDefault();
    var month = $("#month-holder").val();
     if ( $.isNumeric(month) && parseInt(month) < 13) {
                $('#month-error').fadeOut('slow');
                $('#month-holder').removeClass("invalid");

       }  
      else
      {
        $('#month-error').fadeIn('slow');
        $('#month-holder').addClass("invalid");
      }
});
}
})(jQuery);
(函数($){
if($(“#月持有人”).长度){
$(“#月持有人”)。关于(“模糊”,函数(e){
e、 预防默认值();
var月=$(“#月持有人”).val();
如果($.isNumeric(月)和&parseInt(月)<13){
$(“#月误差”).fadeOut('slow');
$(“#月持有人”).removeClass(“无效”);
}  
其他的
{
$(“#月误差”).fadeIn('slow');
$(“#月持有人”).addClass(“无效”);
}
});
}
})(jQuery);

演示:

@Digital Legend:您测试过吗?您的逻辑仍然错误<代码>解析整数(月)>13?
 <input type="text" name="month-holder" id="month-holder" class="input-txt width-65" placeholder="MM" maxlength="2" pattern="\d*" x-autocompletetype="month-holder" required autocomplete="off">
 <div id="month-error"  class="error clearfix">Error</div>
  if(!$.isNumeric(month)){
   if($.isNumeric(month)){
(function($) {     
if($('#month-holder').length){
$('#month-holder').on("blur", function(e){   
    e.preventDefault();
    var month = $("#month-holder").val();
     if ( $.isNumeric(month) && parseInt(month) < 13) {
                $('#month-error').fadeOut('slow');
                $('#month-holder').removeClass("invalid");

       }  
      else
      {
        $('#month-error').fadeIn('slow');
        $('#month-holder').addClass("invalid");
      }
});
}
})(jQuery);
if($.isNumeric(month) && parseInt(month) > 13){
            $('#month-error').fadeIn('slow');
            $('#month-holder').addClass("invalid");
        }

        else
        {
            $('#month-error').fadeOut('slow');
            $('#month-holder').removeClass("invalid");
        }