我试了试:
regno: {
required: true,
maxlength: 20,
noSpace: true
}
有人可以帮助我验证文本字段,开始不允许空格?
您可以使用正则表达式来检查pattern
的前导空格
的例子:
$("#YourForm").validate({
rules: {
txtName: {
pattern: /^(?!s)/
},
},
messages: {
txtName: {
pattern: 'No white space at begining.'
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script>
<form id="YourForm" method="get" action="">
<label>Textbox</label>
<input id="txtName" name="txtName" type="text"/>
</form>
注意:不要忘记在validate.js
后面加上additional-methods.js