gpt4 book ai didi

javascript - 最小长度输入字段验证 - JQuery

转载 作者:可可西里 更新时间:2023-11-01 13:27:01 26 4
gpt4 key购买 nike

我有下面的 JQuery 验证,只是确保在输入字段中写入了一些内容,我在 html 中也有 maxlength。

但是,我希望有人能阐明这种情况,并告诉我如何将某种类型的最小长度添加到下面的 jquery 代码中,这样我就不需要执行任何其他功能了?

 $('#form1').submit(function (e) {
e.preventDefault();
}).validate({
rules: {
txtusername: {
required: true
},
txtfirstname: {
required: true
},
txtemail: {
required: true
},
txtpassword: {
required: true
},
passwordconfirm: {
required: true
}
},
messages: {
txtusername: {
required: "Please enter your Username."
},
txtfirstname: {
required: "Please enter your First Name."
},
txtemail: {
required: "Please enter your Email."
},
txtpassword: {
required: "Please enter your Password."
},
passwordconfirm: {
required: "Please enter your password again."
}
},
errorPlacement: function (error, element) {
error.appendTo(element.parent().prev());
},
submitHandler: function (form, user) {

CheckUser(form);
return false;
}
});

示例 HTML -

<div data-role="fieldcontainer">
<label for="txtusername" data-theme="d">Username:</label>
<input type="text" id="txtusername" name="txtusername" maxlength="12" placeholder="Enter Username"/>
</div>

最佳答案

你可以像下面这样使用:

rules:{
txtusername: {
required: true,
minlength: 3
},
}

关于javascript - 最小长度输入字段验证 - JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36264511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com