topical media & game development

talk show tell print

#javascript-code-07-date.js / js



  // A generic function for checking to see if an input element has
  // a date entered into it
  function checkDate( elem ) {
      // Make sure that something is entered, and that it
      // looks like a valid MM/DD/YYYY date
      return !elem.value || /^\d{2}\/\d{2}\/\d{2,4}/.test(obj.value);
  }
  
  // Get an input element to check
  var elem = document.getElementById("date");
  
  // Check to see if the field contains a valid date
  if ( ! checkDate( elem ) ) {
      alert( "Field is not a date." );
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.