How to leave the field mandatory when the value is 0.00 using jquery validate?
Here is an example image:
Asyoucanseetheimageabove,thepersondidnotenterthevalue,whenclickingtheacceptbutton,jqueryvalidatenormallyworksthefollowingimage:
Nowtheproblemiswhenyouentervalue0.00.Hereistheimage:
Asyoucanseetheimageabove,thevaluecannotbe0.00,itmustbeatleast0,01.
Followthecodebelow:
Html:
<formid="myform">
<input type="text" class="form-control" value="@Model.Valor" id="valor" name="valor" placeholder="Digite o seu valor">
</form>
Javascript :
$('#valor').priceFormat({
prefix: 'R$ ',
centsSeparator: ',',
thousandsSeparator: '.'
});
Jquery Validate :
$(document).ready(function () {
$("#myform").validate({
ignore: ":hidden",
rules: {
valor: { required: true }
},
messages: {
valor: "<span style=\"color: #a94442;\">Campo Valor é obrigatório *</span>"
},
highlight: function (element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error');
},
submitHandler: function (form) { etc ....}
I use Jquery-Price-Format . When entering value 0.00, jquery should show warning. When it is 0,01 take the jquery validate warning. That is, if it equals 0.00, show red warning. Any solution?