I try:
regno: {
required: true,
maxlength: 20,
noSpace: true
}
Can somebody assist me to validate text field that the beginning does not allow space?开发者_如何学编程
You can use regular expression to check leading white space with pattern
from validation plugin additional method.
Example:
$("#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>
Note: Don't forget to add additional-methods.js
after validate.js
精彩评论