By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

problem in validating date nd time in same textfield

100+
P: 149
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
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function f(){
  3. var re= /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
  4. var re1= /^(\d{2}):(\d{2}):(\d{2})/;
  5. var el= document.getElementById('d');
  6. var M= el.value.match(re);
  7. var M1= e1.value.match(re1);
  8. var msg= M+M1;
  9. if (!msg) {
  10.     alert("correct");
  11. }
  12. else {
  13. alert("wrong");}
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <form id="form1" name="form1" action="index.php" onsubmit="return f()">
  19. yyyy-mm-dd hh:mm:ss<input type="text" id="d"> <input type="submit" value="send me"></form>
  20. </body>
  21. </html>
Sep 28 '10 #1
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
currently youíre checking for either date or time, donít know if thatís intended Ö
Sep 28 '10 #2

100+
P: 149
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
Sep 28 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
remove the ^ from the time RegExp.
Sep 28 '10 #4

100+
P: 149
hi,
i had done wht u suggested..but im not getting any alert msg that it is correct...cn u once chk my code.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function f(){
  3. var re= /^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/;
  4. var re1= /(\d{2}):(\d{2}):(\d{2})/;
  5. var el= document.getElementById('d');
  6. var M= el.value.match(re);
  7. var M1= e1.value.match(re1);
  8. var msg= M+M1;
  9. if (!msg) {
  10.     alert("correct");
  11.     return true;
  12. }
  13. else {
  14.     alert("wrong");
  15.     return false;
  16. }
  17. }
  18.  
  19. </script>
  20. </head>
  21. <body>
  22. <form id="form1" name="form1" action="index.php" onsubmit="return f()">
  23. yyyy-mm-dd hh:mm:ss<input type="text" id="d"> <input type="submit"
  24.     value="send me"></form>
  25. </body>
  26. </html>
Sep 28 '10 #5

100+
P: 149
any help regardng my post..
Sep 28 '10 #6

Dormilich
Expert Mod 5K+
P: 8,639
you have a typo on line #7 (e1 instead of el)

additionally, what do you expect msg be and is your test method sensible?
Sep 29 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.