Click here to Skip to main content
15,848,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Am trying to do a validation using minlength. The code works on jsfiddle but it doesn't work on my html page.
JSfiddle

Full code:
XML
<html>
<head>
</head>
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){
$("#form").validate({
        rules: {
            'phonenumber': {
                required: true,
                minlength: 10
            }
        }
    });
});
</script>
<form action="order.php" method="post" id="form">
Your phone number :
        <input name="phonenumber" type="text" id='phonenumber' maxlength="10" autocomplete="off" onkeypress='return event.charCode >= 48 && event.charCode <= 57' placeholder="phonenumber">
<input type="submit" />
</form>
</body>
</html>
Posted
Updated 28-Dec-14 21:44pm
v3

1 solution

Considering what you have working in the fiddle:

You need to add a script reference for JQuery's validation library (you may use following (on a CDN)):

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js


Also, you need to remove an extra ) from your script.

Hope this helps.
 
Share this answer
 
v4
Comments
404 valid 29-Dec-14 4:47am    
Seems like me not adding the validation reference and the extra ) was making the script not to work. But now it works fine. Thanks :)

script change:
window.onload = function ()
{
$("#form").validate({
rules: {
'phonenumber': {
required: true,
minlength: 10
}
}
});
};
Agent__007 29-Dec-14 4:53am    
You are most welcome. Glad it helped.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900