Why does the script not only accept the letter F?

2

I made a regular expression to accept values from 0.0 to 10.0 and the letter F and with it I'm having problems, it ends up denying in the msg of AddMethod () itself.

    <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>
    
asked by anonymous 27.02.2014 / 21:22

2 answers

1

The problem is in the rules ( rules ) ... replace nota: "required nota" with nota: true

        rules:{
            nota:{
                nota: true,
                required: true
            }
        },
    
27.02.2014 / 21:52
0

Your regular expression should not look like this:

^(([F]{0,1})|((([1]{1}[0]{1})\.([0]{1}))|((([0]{1})(\d){1}))\.(\d{1})))?$

I think you've committed a small typo . Changed% by% by% by%.

    
27.02.2014 / 21:34