Shopping cart form with JQuery validation

I thought this would be a good starting point for anyone who is creating a shopping cart and needs a form to process the details. Although the form comes with some JQuery validation I would recommend that you also add server side validation for those 5% of users that have javascript turned off.

Of particular note is the 'expiryDate' function that has been added.

view plain print about
1$.validator.addMethod('expiryDate', function(value, element){ var presentDate = new Date(); var selectedDateHash = parseInt($('#expiryMonth').val(), 10) + parseInt(($('#expiryYear').val() * 12), 10); var presentDateHash = (presentDate.getMonth()+1) + (presentDate.getFullYear() * 12); if (selectedDateHash > presentDateHash) { $('#expiryMonth').removeClass('invalidFormField'); $('#expiryYear').removeClass('invalidFormField'); } else { $('#expiryMonth').addClass('invalidFormField'); $('#expiryYear').addClass('invalidFormField'); } return this.optional(element) || selectedDateHash > presentDateHash; }, 'this credit card has expired');
This makes sure that the expiry date has not passed. You can view the demo here

TweetBacks
Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.004. Contact Blog Owner