473,403 Members | 2,071 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,403 software developers and data experts.

validating time

20
Expand|Select|Wrap|Line Numbers
  1. var err_str="";
  2. function validate_grid(value,id,ind)
  3.     {
  4.         if(ind==1 || ind==2)
  5.         {
  6.             var patt=/^([0][0-9]|[0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/;
  7.             if(!patt.test(value))
  8.             {
  9.                 mygrid.setCellTextStyle(id,ind,"background-color:yellow;");
  10.                 if(err_str!="")
  11.                     err_str+="\n"+(ind+1)+".Enter numbers and (:) only..[ex.05:00 24hr format]";
  12.                 else
  13.                     err_str=(ind+1)+".Enter numbers and (:) only..[ex.05:00 24hr format]";
  14.                 return false;
  15.             }
  16.             else
  17.             {
  18.                 mygrid.setCellTextStyle(id,ind,"background-color:white;");
  19.                 return true;
  20.             }
  21.         }
  22. }
  23.  
here ind==1 is from-time and ind==2 is to-time,from-time should not be greater than to-time and to-time should not be less than from-time
ex:05:00-09:00(true)
09:00-08:00(false).
Jan 17 '12 #1
3 1660
acoder
16,027 Expert Mod 8TB
One way to do this is to use the Date object:
  1. Create 2 dates using the from/to times
  2. Compare them
Jan 24 '12 #2
narinas
20
can u show me how to do that using the above format.
Jan 27 '12 #3
acoder
16,027 Expert Mod 8TB
As I mentioned, it's one way. See below if you want to use dates.

Another method is to split on the ":" to get the hours and minutes and then compare the hours. If equal, compare the minutes. That should be straightforward. If not, post your attempt.

If using the Date method, see https://developer.mozilla.org/en/Jav...l_Objects/Date for info. on Dates.
It has enough to get you started on creating a Date (split on ":" and create using either new or set** methods.

To compare, use the comparison operator (e.g. < or >) on 2 Date objects.
Jan 28 '12 #4

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

Similar topics

6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
2
by: David | last post by:
Hello. I'm new in regular expresions. I want to validate time... For example: Valid times -> 12:30, 19:59, 0:00, 1:15, 05:40 Invalid times -> 24:00, 12:61, 53:20, 50:60 Can anybody show me...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
6
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
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...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.