problem in validating date nd time in same textfield

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhuriks
    New Member
    • Jun 2010
    • 149

    problem in validating date nd time in same textfield

    hi,
    in my application i need to enter date nd time in the same textbox...if i run individually it is wrkng fine but wen i combine it is nt wrking fine...can anyone help me out
    Code:
    <script type="text/javascript">
    function f(){
    var re= /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
    var re1= /^(\d{2}):(\d{2}):(\d{2})/;
    var el= document.getElementById('d');
    var M= el.value.match(re);
    var M1= e1.value.match(re1);
    var msg= M+M1;
    if (!msg) {
    	alert("correct");
    }
    else {
    alert("wrong");}
    }
    </script>
    </head>
    <body>
    <form id="form1" name="form1" action="index.php" onsubmit="return f()">
    yyyy-mm-dd hh:mm:ss<input type="text" id="d"> <input type="submit" value="send me"></form>
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    currently you’re checking for either date or time, don’t know if that’s intended …

    Comment

    • madhuriks
      New Member
      • Jun 2010
      • 149

      #3
      hi,
      im chkng for both in the same text field nd i need to get in the text field as '2010-09-28 11:50:25 'like that format..i need that one..cn u suggest me where to change

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        remove the ^ from the time RegExp.

        Comment

        • madhuriks
          New Member
          • Jun 2010
          • 149

          #5
          hi,
          i had done wht u suggested..but im not getting any alert msg that it is correct...cn u once chk my code.
          Code:
          <script type="text/javascript">
          function f(){
          var re= /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
          var re1= /(\d{2}):(\d{2}):(\d{2})/;
          var el= document.getElementById('d');
          var M= el.value.match(re);
          var M1= e1.value.match(re1);
          var msg= M+M1;
          if (!msg) {
          	alert("correct");
          	return true;
          }
          else {
          	alert("wrong");
          	return false;
          }
          }
          
          </script>
          </head>
          <body>
          <form id="form1" name="form1" action="index.php" onsubmit="return f()">
          yyyy-mm-dd hh:mm:ss<input type="text" id="d"> <input type="submit"
          	value="send me"></form>
          </body>
          </html>

          Comment

          • madhuriks
            New Member
            • Jun 2010
            • 149

            #6
            any help regardng my post..

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              you have a typo on line #7 (e1 instead of el)

              additionally, what do you expect msg be and is your test method sensible?
              Last edited by Dormilich; Sep 29 '10, 11:33 AM.

              Comment

              Working...