validate input date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AliHabib
    New Member
    • Dec 2008
    • 11

    validate input date

    Code:
    <script language="javascript">
    
    			function validateDate(fld) {
    				var RegExPattern = ((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))
    				var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. 30/2/2000 would not be accepted.\nFormay dd/mm/yyyy.';
    				if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
    					alert('Date is OK'); 
    				} else {
    					alert(errorMessage);
    					fld.focus();
    				} 
    			}
    
    </script>
    and in the body
    Code:
    <tr>
    					<td>
    						From Date: <Input type="text" style="COLOR: white; BACKGROUND-COLOR: #728fd6; face: verdana" size="10"
    							name="TxtFrom" ID="Text4" onblur="validateDate(this);" />
    					</td>
    					<td>
    						To Date: <Input type="text" style="COLOR: white; BACKGROUND-COLOR: #728fd6; face: verdana" size="10"
    							name="TxtTo" ID="Text5" onblur="validateDate(this);" />
    					</td>
    				</tr>
    				<tr>
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    The quick red fox jumps over the lazy brown dog.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      It's wonderful that you have implemented a solution to validate dates...
      Is there a problem with the above posted code?
      Do you have a question to ask?

      -Frinny

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Also, this doesn't seem to be related directly to ASP. This is a strict javascript solution.

        Jared

        Comment

        Working...