Validating date in javascript

Description: This script validates a date field to ensure it's in the format mm/dd/yyyy.It also intelligently checks that the date ranges are valid, so something like 02/30/2005 is caught.When capturing information for insertion into a database, or use in other processing, it's important to control what the user can enter.In this example, the date fields will only accept input that matches the pattern 'dd/mm/yyyy' (this could just as easily be changed to 'yyyy-mm-dd' or 'mm/dd/yyyy').

validating date in javascript-41validating date in javascript-26validating date in javascript-4

//-------------------------------------------------------------------------- function is Valid Date(date Str) //These functions go between the tags.options can be either a date string in the format of YYYY-MM-DD or a Date object.If the form need to validate start and end date, you should take a look at the Validating fields that depend on each other or Compraing dates example.//Begin function checkdate function checkdate(input) //Begin function button1_onclick //This makes sure that even if it somehow got past the original error check, //the report won't run unless the date format is correct.function button1_onclick(ctrl) //End function button1_onclick //This goes in the BODY portion of the HTML Add this phrase to any date control you want to call the function from: on Change="checkdate(this)" //We had to use onchange instead of onblur //because our call center software was interfering //with HTML code and causing the control to lose focus - // we ended up in an infinite loop of error messages.

Leave a Reply