Reputation: 829
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>
Upvotes: 2
Views: 1932
Reputation: 4794
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;
}
});
Upvotes: 2