2

Can anyone please tell me why this method doesn’t work here .(‘ alphanumeric:true’) Here is my code

$(document).ready(function () {

    $('#myform').validate({ // initialize the plugin
        rules: {
            fname: {
                required: true,
     alphanumeric:true, //I’m not sure about this if this is wrong  please tell me

            },
        },


        messages: {
            fname: "Please enter your first name",

        },


        submitHandler: function (form) { // for demo
            alert('valid form submitted'); // for demo
            return false; // for demo
        }
    });

});

HTML

<html>
    <head> 
        <script type="text/javascript" src="jquery.min.js"></script> 
        <script type="text/javascript" src="jQuery.validate.min.js"></script> 
        <script type="text/javascript" src="final.js"></script> 
        <script type="text/javascript" src="additional-methods.js"></script> 
    </head> 
    <body> 
        <form id="myform"> 
            <input type="text" name="fname" /> <br/> 
            <input type="text" name="field2" /> <br/> 
            <input type="submit" /> 
        </form> 
    </body> 
</html>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Erandi
  • 719
  • 3
  • 7
  • 16

1 Answers1

2

This may not be your only issue, but I can tell you that this will not work in older versions of IE.

Although it is perfectly valid syntax, per JS standards, IE does not like it when you leave in trailing commas after the last element of an array.

I have noted these issue commas in your code, below:

$('#myform').validate({ // initialize the plugin
    rules: {
        fname: {
            required: true,
            alphanumeric:true, //trailing comma
        }, //trailing comma
    },


    messages: {
        fname: "Please enter your first name", //trailing comma
    },


    submitHandler: function (form) { 
        alert('valid form submitted'); 
        return false; 
    }
});
Zachary Kniebel
  • 4,686
  • 3
  • 29
  • 53
  • This is more of a comment since it does not answer the OP's question. – Jay Blanchard May 12 '14 at 18:47
  • @JayBlanchard - I disagree, as I did point out a bug in his code. He did not reference a specific browser, so I started with the basics. I was about to reference your comment in my answer, however, as the more likely direct cause of the issue, but was going to give you the option to post it as an answer, first. – Zachary Kniebel May 12 '14 at 18:50
  • Go ahead and mention the other issue, because that is likely the bigger problem here. I agree about the commas, he may not be seeing that issue because he may not be testing in IE. BTW - I think IE 10 and 11 come on board and don't fuss about the commas, but I have not tested that. – Jay Blanchard May 12 '14 at 18:54
  • 1
    @ Jay & Zachary ... not he ..she :P ..I'm using chrome – Erandi May 12 '14 at 18:56
  • @JayBlanchard - I believe that you are correct, and I meant to say "older IE." I will update my post. My apologies, Erandi. – Zachary Kniebel May 12 '14 at 18:58
  • My apologies too, @Erandi. :) – Jay Blanchard May 12 '14 at 19:01
  • Still I couldn't solve this problem @ Zachary ..friend,your code didn't work – Erandi May 12 '14 at 19:13