FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time validation
#1
Question 
[size=x-small]
Hello there,

Maybe a silly question from a newbie.....
Anyone knows how to implement a RSV rule to compare two time values?
format: hh:mm.

I would like to prevent users to fill in wrong time values (time in textbox2 earlier then time in textbox1)

Code:
</select> <select name="BW" style=
    "position:absolute;left:300px;top:35px;width:80px;z-index:50; height: 20px;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; font-style: normal; font-variant: normal; font-weight: normal">
    <option value=""></option>
      <option value="06:00">
        06:00
      </option>

      <option value="06:15">
        06:15
      </option>

      <option value="06:30">
        06:30
      </option>

      <option value="06:45">
        06:45
      </option>

      <option value="07:00">
        07:00
      </option>

      <option value="07:15">
        07:15
      </option>

      <option value="07:30">
        07:30
      </option>

      <option value="07:45">
        07:45
      </option>

      <option value="08:00">
        08:00
      </option>

      <option value="08:15">
        08:15
      </option>

      <option value="08:30">
        08:30
      </option>

      <option value="08:45">
        08:45
      </option>

      <option value="09:00">
        09:00
      </option>

      <option value="09:15">
        09:15
      </option>

      <option value="09:30">
        09:30
      </option>

      <option value="09:45">
        09:45
      </option>

      <option value="10:00">
        10:00
      </option>

      <option value="10:15">
        10:15
      </option>

      <option value="10:30">
        10:30
      </option>

      <option value="10:45">
        10:45
      </option>

      <option value="11:00">
        11:00
      </option>

      <option value="11:15">
        11:15
      </option>

      <option value="11:30">
        11:30
      </option>

      <option value="11:45">
        11:45
      </option>

      <option value="12:00">
        12:00
      </option>

      <option value="12:15">
        12:15
      </option>

      <option value="12:30">
        12:30
      </option>

      <option value="12:45">
        12:45
      </option>

      <option value="13:00">
        13:00
      </option>

      <option value="13:15">
        13:15
      </option>

      <option value="13:30">
        13:30
      </option>

      <option value="13:45">
        13:45
      </option>

      <option value="14:00">
        14:00
      </option>

      <option value="14:15">
        14:15
      </option>

      <option value="14:30">
        14:30
      </option>

      <option value="14:45">
        14:45
      </option>

      <option value="15:00">
        15:00
      </option>

      <option value="15:15">
        15:15
      </option>

      <option value="15:30">
        15:30
      </option>

      <option value="15:45">
        15:45
      </option>

      <option value="16:00">
        16:00
      </option>

      <option value="16:15">
        16:15
      </option>

      <option value="16:30">
        16:30
      </option>

      <option value="16:45">
        16:45
      </option>

      <option value="17:00">
        17:00
      </option>

      <option value="17:15">
        17:15
      </option>

      <option value="17:30">
        17:30
      </option>

      <option value="17:45">
        17:45
      </option>

      <option value="18:00">
        18:00
      </option>

      <option value="18:15">
        18:15
      </option>

      <option value="18:30">
        18:30
      </option>
    </select> <select name="VZ" style=
    "position:absolute;left:300px;top:75px;width:80px;z-index:51; height: 20px;;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; font-style: normal; font-variant: normal; font-weight: normal">
    <option value=""></option>
      <option value="06:00">
        06:00
      </option>

      <option value="06:15">
        06:15
      </option>

      <option value="06:30">
        06:30
      </option>

      <option value="06:45">
        06:45
      </option>

      <option value="07:00">
        07:00
      </option>

      <option value="07:15">
        07:15
      </option>

      <option value="07:30">
        07:30
      </option>

      <option value="07:45">
        07:45
      </option>

      <option value="08:00">
        08:00
      </option>

      <option value="08:15">
        08:15
      </option>

      <option value="08:30">
        08:30
      </option>

      <option value="08:45">
        08:45
      </option>

      <option value="09:00">
        09:00
      </option>

      <option value="09:15">
        09:15
      </option>

      <option value="09:30">
        09:30
      </option>

      <option value="09:45">
        09:45
      </option>

      <option value="10:00">
        10:00
      </option>

      <option value="10:15">
        10:15
      </option>

      <option value="10:30">
        10:30
      </option>

      <option value="10:45">
        10:45
      </option>

      <option value="11:00">
        11:00
      </option>

      <option value="11:15">
        11:15
      </option>

      <option value="11:30">
        11:30
      </option>

      <option value="11:45">
        11:45
      </option>

      <option value="12:00">
        12:00
      </option>

      <option value="12:15">
        12:15
      </option>

      <option value="12:30">
        12:30
      </option>

      <option value="12:45">
        12:45
      </option>

      <option value="13:00">
        13:00
      </option>

      <option value="13:15">
        13:15
      </option>

      <option value="13:30">
        13:30
      </option>

      <option value="13:45">
        13:45
      </option>

      <option value="14:00">
        14:00
      </option>

      <option value="14:15">
        14:15
      </option>

      <option value="14:30">
        14:30
      </option>

      <option value="14:45">
        14:45
      </option>

      <option value="15:00">
        15:00
      </option>

      <option value="15:15">
        15:15
      </option>

      <option value="15:30">
        15:30
      </option>

      <option value="15:45">
        15:45
      </option>

      <option value="16:00">
        16:00
      </option>

      <option value="16:15">
        16:15
      </option>

      <option value="16:30">
        16:30
      </option>

      <option value="16:45">
        16:45
      </option>

      <option value="17:00">
        17:00
      </option>

      <option value="17:15">
        17:15
      </option>

      <option value="17:30">
        17:30
      </option>

      <option value="17:45">
        17:45
      </option>

      <option value="18:00">
        18:00
      </option>

      <option value="18:15">
        18:15
      </option>

      <option value="18:30">
        18:30
      </option>
    </select>
Reply
#2
Hey bvdveen,

For something custom like this, you'll definitely need to look into the custom function option. What that does is let you supplement the existing validation rules (required, valid email, is numeric, etc.) with your own custom ones. Check out the "custom validation rules" link on the top right of this page:
http://www.benjaminkeen.com/software/rsv/standalone/

Basically it works by adding a rule like so:

Code:
rules.push("function,check_times");

Then writing your own function that would do the manual labour of figuring out what was valid and what wasn't:

Code:
function check_times() {
  // do stuff here
}

The return values of that function need to be a particular format, as is described in that page above.

Hope this at least gets you on the right track...!

- Ben
Reply
#3
(Jan 16th, 2010, 11:45 AM)Ben Wrote: Hey bvdveen,

For something custom like this, you'll definitely need to look into the custom function option. What that does is let you supplement the existing validation rules (required, valid email, is numeric, etc.) with your own custom ones. Check out the "custom validation rules" link on the top right of this page:
http://www.benjaminkeen.com/software/rsv/standalone/

Basically it works by adding a rule like so:

Code:
rules.push("function,check_times");

Then writing your own function that would do the manual labour of figuring out what was valid and what wasn't:

Code:
function check_times() {
  // do stuff here
}

The return values of that function need to be a particular format, as is described in that page above.

Hope this at least gets you on the right track...!

- Ben

Hi Ben!

Thanks for your answer.
The problem - as you may have concluded already :-) - is that I an not sure how to write the code correctly. Believe me I have read over and over your example of a custom validation rule (prime numbers)
I simply don't know how to make sure my rule works.

I need something like:

field a = "begin_"time"
array: 06:00|06:15|06:30|06:45|07:00(etc).......|19:00
field b = "end_time"
array: 06:00|06:15|06:30|06:45|07:00(etc).......|19:00

rule: field b >= field a.

A solution I have thought of might be:

field a = begin_hour
array: 06|07|08|.....|19
field b = begin_minute
array:00|15|30|45
field c = end_hour
array: 06|07|08|....|19
field d = end_minute
array = 00|15|30|45

rule 1:
field c>=field a
rule 2:
field d<>field b

maybe with one more hint from you I could do it!
Sorry to have bothered you again with this...

Greetings

bvdveen
Reply
#4
Hey bvdveen,

No worries! It's always a bit rocky when you start programming.... but then you get hooked. Smile

I'd tackle the problem slightly differently, but your solution would work too. Take a look at the following code (I confess I haven't tested it, but the logic is sound):

Code:
function check_times()
{
    // get the values in the two dropdowns (you'll need to replace
    // "formnamehere" with the name attribute of your form)
    var time1 = document.formnamehere.BW.value;
    var time2 = document.formnamehere.VZ.value;
    
    // if either are empty, just do nothing. If the fields ARE required,
    // just add another RSV "required" rule BEFORE calling this custom function
    if (!time1 || !time2)
    {
        return true;
    }

    // split the info in each time on the ":" character
    var time1_info  = time1.split(":");
    var time1_hours = parseInt(time1_info[0]); // parseInt sucks, but it's OK here
    var time1_mins  = parseInt(time1_info[1]);
    
    var time2_info = time2.split(":");
    var time2_hours = parseInt(time2_info[0]);
    var time2_mins  = parseInt(time2_info[1]);
    
    // the error message is always going to be the same, so let's just stash it
    // in a variable here so we don't have to type it out multiple times.
    var errorInfo = [document.formnamehere.VZ, "Sorry, please enter a later time."];

    // alright! Now we do our validation. First check the hours: if the hour in time2
    // is less than time1, Houston we have a problem
    if (time2_hours < time1_hours)
    {
        return [errorInfo];
    }
    else if (time2_hours == time1_hours)
    {
        // here, the user entered the same hour for both. So,check that the
        // mins in time2 isn't greater of equal to that in time1
        if (time2_mins <= time1_mins)
        {
            return [errorInfo];
        }
    }

    // we're good!
    return true;    
}

Let me know how it goes!

- Ben
Reply
#5
You have given a good information. I really appreciate sharing this great post.This is really very helpful for me .
Reply
#6
Programing is my Life and I am crazy of programing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)