Here I needed to make sure that the user input was formatted correctly for a MySQL database. The javascript calendar code was set to automatically input the date into the text field in the correct format, but the user still had the option to type it in manually. This was the Prototype validator I used to verify that the user had entered it correctly as ‘YYYY-MM-DD’:
1 2 3 4 5 |
<script type="text/javascript"> Validation.add('required-date-format','Please Enter date as YYYY-MM-DD. Click the calendar icon to select a date.', function(v) { return !Validation.get('IsEmpty').test(v) && /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])$/.test(v); }); var warrantyregistrationForm = new VarienForm('warrantyregistrationForm', true); </script> |