Validate the Date : Date : Regular Expressions JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Regular Expressions » Date »

 

Validate the Date

















<HTML>
<HEAD>
<SCRIPT>
function checkDate(testStr) {
   var pattern = /b(d{2})/(d{2})/(d{4})b/;
   var result = testStr.match(pattern);
   if (result != null)
      return "Well done.";
   else
      return "You didn't input a date in the specified pattern.";
}
</SCRIPT>
</HEAD>
<BODY>
Check a date format today!
<FORM name="theForm">
Enter a date in mm/dd/yyyy format:
<INPUT type=text name=testStr size=20 maxlength=10>
<INPUT type=button 
       name="theButton" 
       value="Verify the Format"    
       onClick="alert(checkDate(document.theForm.testStr.value))";>
</FORM>  
</BODY>
</HTML>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Regular Expressions
» Date