My current validator for accepting integer is
$( "#UserForm" ).validate({
rules: {
contact: {
required: true,
number: true,
minlength: 6,
}
}
});
It works fine
But now i want to make change in it so as to accept spaces also.
What should be my code?Please help i'm beginner in jquery
You can use the pattern rule defined in the additional-method.js file
jQuery(function($) {
$("#UserForm").validate({
rules: {
contact: {
required: true,
pattern: /^[\d\s]+$/,
minlength: 6,
}
},
messages: {
contact: {
pattern: 'Please enter digits or space characters only'
}
}
});
});
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/additional-methods.js"></script>
<form id="UserForm" method="post" action="">
<div>
<input name="contact" />
</div>
<input type="submit" class="button" value="Submit" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With