2
I made a regular expression to accept values from 0.0 to 10.0 and the letter F and precisely with it I’m having problems, ends up denying in Addmethod’s own msg().
<html>
<head>
<script src="jquery-2.0.3.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script>
$(document).ready( function() {
//Método para verificar as horas com uso de expressão regular
$.validator.addMethod("nota", function(value, element) {
return this.optional(element) || /^(([F]{0-1})|((([1]{1}[0]{1})\.([0]{1}))|((([0]{1})(\d){1}))\.(\d{1})))?$/i.test(value);
}, "Por favor entre com uma nota válida.");
$("#formularioContato").validate({
// Define as regras
rules:{
nota:{
nota: "required nota",
required: true
}
},
messages:{
nota:{
required: "Digite uma nota válida ou o conceito F",
range: "O valor do dia deve estar entre 0.0 a 10.0 ou F"
}
}
});
});
</script>
<script src="jquery.maskedinput.js" type="text/javascript"></script>
<script>
jQuery(function($){
$("#nota").mask("*9.9");
});
</script>
</head>
<body><form id="formularioContato" method="post">
<div align="center">
<ul>
<li>
<label>Nota:</label><input type="text" id="nota" name="nota"></span><br />
</li>
</ul>
</div>
<input class="submit" type="submit" value="Enviar" />
</form>
</body>
</html>
The mask Mask("*9.9") should not be a Mask("A9.9")? http://igorescobar.github.io/jQuery-Mask-Plugin/
– CCastro
I think the expression could be
^(F|10\.0|\d\.\d)$
, because "10.0" is valid but "11.0" is no longer valid... if the decimal is optional, it can be so:^(F|10(\.0)?|\d(\.\d)?)$
– J. Bruni
J.Bruni that you sent me worked because it does not accept the 09.0
– user5988