473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

problem in validating date nd time in same textfield

149 100+
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
6 1654
Dormilich
8,658 Expert Mod 8TB
currently you’re checking for either date or time, don’t know if that’s intended …
Sep 28 '10 #2
madhuriks
149 100+
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
8,658 Expert Mod 8TB
remove the ^ from the time RegExp.
Sep 28 '10 #4
madhuriks
149 100+
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
madhuriks
149 100+
any help regardng my post..
Sep 28 '10 #6
Dormilich
8,658 Expert Mod 8TB
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

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

Similar topics

1
by: simina | last post by:
Hi... I have an "appointments" page where the user should (or not necessarily) choose a date and time for his appointment, from 6 combo boxes:year, month, day, hour, minute and AM or PM, without...
7
by: Don | last post by:
Hi all, With regards to the following, how do I append the datetimestamp to the filenames in the form? The files are processed using the PHP script that follows below. Thanks in advance,...
6
by: leo | last post by:
Hello there Im having trouble in storing blank or space value on a variable wich data type is Date/Time, if i make a statement like this Field Data Type...
5
by: Javier | last post by:
I have a field type Date/Time that automatically defaults to Now(). I'm having a problem writing a query that will retrieve all the records for a specific date the user to enters when prompted. I...
1
by: E. Liepins | last post by:
I am working on a vehicle database. We track when a vehicle is borrowed and when it is returned. We also track the number of kilometres travelled on a particular trip. There are several tables:...
3
by: Marauderz | last post by:
Hello guys, got a little question regarding the regional language settings . Anyway I got a Windows 2003 Server machine that was installed with the date format "dd/MM/yyyy" and location still...
17
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
4
by: Michel Posseth [MCP] | last post by:
I have a problem with the date time picker validate event wich i believe is a bug How to reproduce : throw on a form a date time picker control and a textbox control select the validating...
4
nirmalsingh
by: nirmalsingh | last post by:
hi, my code is ------------------- string demo="01-01-2007 04:59:21 PM"; DateTime dtDate=Convert.ToDateTime(demo); string strDate = dtDate.ToString("yyyy-MM-dd hh:mm:ss AM/PM");...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.