-2

I try:

regno: {
           required: true,
           maxlength: 20,
           noSpace: true
       }

Can somebody assist me to validate text field that the beginning does not allow space?

Sparky
  • 98,165
  • 25
  • 199
  • 285

1 Answers1

0

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

4b0
  • 21,981
  • 30
  • 95
  • 142