/ Published in: JavaScript
Is their a better solution?
Expand |
Embed | Plain Text
<script type="text/javascript"> jQuery(document).ready(function($) { $.validator.addMethod("validate-digits-range", function(value, element) { var result = this.optional(element) || /^\d+$/.test(value); $.each($(element).attr("class").split(" "), function(index, class) { if (result && /^digits-range-[0-9]+-[0-9]+$/.test(class)) { var min = parseInt(class.split('-')[2], 10); var max = parseInt(class.split('-')[3], 10); result = (value >= min) && (value <= max); if (!result) { $.validator.messages["validate-digits-range"] = $.validator.format("Please enter a value between {0} and {1}", min, max); } return false; } } ); return result; }, $.validator.format("Please enter a value between {0} and {1}") ); $("#form-validate").validate(); } ); </script>
You need to login to post a comment.
