Search code examples
jqueryvalidationpluginsletters

jQuery validation plugin - "lettersonly" function


i am quite new to jQuery and I'm trying to use the lettersonly function for my signup form. I have looked at this question already but implementing it didn't seem to work for me.

Here's my code:

            <form class="kennzeichen-input-big" action="step1.php">
                <input type="text" name="kuerzel" id="kuerzel" style="font-size:50px;" maxlength="3" required> 
                <input type="submit" value="Zur Reservierung" class="btn signup" style="width:auto; margin-top:15px; margin-left:20px;">


</form>

    <script>
        $("form").validate(
        { rules: { ('#kuerzel'): { lettersonly: true } } }
        );
    </script>

I assume the problem is with the "myField" tag? I have tried several things, but didnt get it to work. I did include the additional functions, too.


Solution

  • All you're missing is that the field must be referenced by it's name attribute in the Validate call.

        $("form").validate(
        { rules: { ('#kuerzel'): { lettersonly: true } } }
        );
    

    Becomes:

        $("form").validate(
        { rules: { kuerzel: { lettersonly: true } } }
        );
    

    That's it, assuming you aren't seeing any other errors on the page...