Robert Granlund
asked on
jQuery Validate
I use validatejs to validate form fields
http://jqueryvalidation.org/
The plugin uses field names to validate. I need to use the field ID's but it does not seem to be working. Can anyone tell me what I am doing wrong?
http://jqueryvalidation.org/
The plugin uses field names to validate. I need to use the field ID's but it does not seem to be working. Can anyone tell me what I am doing wrong?
<script>
$().ready(function(){
$("#update_cart_form").validate({ rules: {
"#purchase_price": {
digits: true
},
"#accessories_value": {
digits:true,
max:5000
},
"#contact_email": {
email:true,
regex:"^((\"[\\w\\s-]+\")|([\\w-]+(?:\\.[\\w-]+)*)|(\"[\\w\\s-]+\")([\\w-]+(?:\\.[\\w-]+)*))(@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-zA-Z]{2,6}(?:\\.[a-zA-Z]{2})?)$)|(@\\[?((25[0-5]\\.|2[0-4][0-9]\\.|1[0-9]{2}\\.|[0-9]{1,2}\\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\]?$)"
},
},
messages: {
"#purchase_price": {
digits: "Only a numeric value allowed"
},
"#accessories_value": {
digits: "Only a numeric value allowed",
max: "You can not have over $5000 in accessories"
},
"#contact_email": {
email: "You must supply a valid contact email address"
}
},
errorElement: "div"
});
});
</script>
ASKER
For some reaso, that did not work. I'm sure I have missed something obvious in the code. I'll go over it again, thoroughly and if it still does not work, I'll re-post my updated code..
Sorry, don't knock yourself out. I was mistaken. All validate fields must have a unique name attribute. You can however use any selector if you use the rules add method.
http://jqueryvalidation.org/rules#.22add.22rules
http://jqueryvalidation.org/rules#.22add.22rules
ASKER
I wrote it but It does not seem to work correctly.
$().ready(function(){
$("#update_cart_form").validate({ rules: {
$( "#purchase_price" ).rules( "add", {
required: true,
digits:true,
messages: {
required: "Please enter a purchase price",
digits: "please enter numbers only"
}
}
});
errorElement: "div"
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use any attribute identifier you need by enclosing it in quotes like this:
Open in new window