• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

2. Numbers and Dates > 2.12. Validating a Date

Validating a Date

NN 4, IE 4

Problem

You want to validate a date entered by the user in a form.

Solution

Use the checkDate( ) function shown in the Discussion. This function takes a text input element as its sole argument and expects the user to enter a date value in either mm / dd / yyyy or mm - dd - yyyy format. For example, the following validation function could be triggered from an onchange event handler of a date entry form field:

function validateDate(fld) {
    if (!checkDate(fld)) {
        // focus if validation fails
        fld.focus( );
        fld.select( );
    }
}

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint