JQuery范围表单验证

时间:2017-06-28 17:28:32

标签: javascript jquery jquery-validate

我试图添加以下表格rulset - 范围在1到5之间。

收到以下错误:

  

'意外的令牌['

范围是一个数组,所以我并没有真正理解这个错误。

    $(document).ready(function(){

    $(".formValidation").validate({
        rules:{
            numberRange:{
                required:true,
                range[1,5]
            }
        }
    });
});


<form class = "formValidation">
    <fieldset>
        <legend>Personal information:</legend>
        <p>First name: </p>
        <input type="text" name ="firstName" placeholder = "First name: ">

        <p>Last name: </p>
        <input type="text" name = "lastName" placeholder = "Last name: ">

        <p>A number between 1-5: </p>
        <input type="number" name = "numberRange" placeholder = "Number 1-5: " required>
        <br>
        <br>

        <input type="submit" value = "Submit">
    </fieldset>
</form>

1 个答案:

答案 0 :(得分:0)

预期:来定义它应该是的范围

$(".formValidation").validate({
    rules:{
        numberRange:{
            required:true,
            range:[1,5]
        }
    }
});