An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
December 23, 2021 11:18 am GMT
Original Link: https://dev.to/bikashgosai/jquery-validation-number-2e09
jQuery Validation [Number]
Here is simple jQuery validation.
HTML code:
<form id="formId" method="post"><div class="body"><input class="form-control text-right" type="number" name="fieldName" min="0" max="1000" /></div><div class="footer"><button type="button" onclick="clearValidation()" class="btn btn-sm" >Cancel</button><button id="btnSubmit" type="button or submit" class="btn btn-sm">Submit</button></div></form>
Put this code on document ready.
$("#formId").validate({ rules: { fieldName: { required: true, number: true, min: 1 } }, messages: { fieldName: {//Custom messages required: "Required", min: "Value must be greater than 0" } } });
Check if fields are valid according to rules defined above:
var form = $("#formId"); if (form.valid()) { //do something... }else{return;}
This is code for removing validation on form.
function clearValidation() { var form = $("#formId").validate(); form.resetForm();}
Original Link: https://dev.to/bikashgosai/jquery-validation-number-2e09
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To