FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Verifying time in php
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Verifying time in php [message #179391 is a reply to message #179385] Sun, 14 October 2012 19:03 Go to previous messageGo to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma:
Senior Member
.oO(Peter H. Coffin)

> On Sun, 14 Oct 2012 17:50:48 +0200, Michael Fesser wrote:
>> .oO(houghi)
>>
>>> I am aware of those. However I can not figure out how to do a check on
>>> all of them, without getting lost in if statements.
>>>
>>> See below where '-' means empty, 1 means any digit(s) and A means any no
>>> digit(s). I have not shown all options.
>>> [...]
>>
>> I wouldn't care too much about invalid inputs. Instead I would just take
>> what I get and see what I can do with it.
>>
>> So I would explicitly cast all values to int (invalid or empty values
>> will become 0), then just do a simple range check on all of the three
>> values and then do the math.
>
> Challenging curcumstance: "A" "B" "C" cast to int becomes 0:0:0, which
> is a valid time.

Yes, as expected and intended.

In my scripts I do a similar thing with date inputs. I don't like
separate fields for day, month and year. So I simply accept what I get
from a single field and try to parse it in several ways. If the result
is a valid date, I accept it. If not, it triggers an error message and
shows the form again.

And I would do the same here as described above. If all three values are
empty or invalid, the result will automatically be 0 and can easily be
rejected. And if values like 36h or 90m are accepted as well, even the
range check could be omitted: just cast to int, maybe abs(), and then
calculate the time in seconds, that's it. Why make things more difficult
than necessary?

Micha

--
http://mfesser.de/
Fotos | Blog | Flohmarkt
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Curl chmod file transfer problem...
Next Topic: test
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 16:47:09 GMT 2024

Total time taken to generate the page: 0.04297 seconds