Date and time validation


Ryan Sytsma

How can I validate a time value in an input? Do I need to parse out the text and make sure the parts are valid? Do I need to write JS to do it? Would the Date control handle time somehow? (I did not see any capability of that)



Ryan Sytsma

Here is some additional info and a scenario

I need to validate 4 inputs prior to sending them to a Http Post.

"[inputCrewName]" does not get evaluated at all.

"[dateCrewDate]" always fails validation with a blank input or a value of 9/16/2019.



DecSoft

Hello Ryan,

There are various things to be considered. First of all, maybe, is that the "date" input is very attractive, but, the differences between browsers' implentation can be tricky. Mozilla itself recommend to use two or three Select or Text or Number inputs instead, as you can see, for example, in the sample app Datetime.

Since we can get the separated day, month and year, can be probably better to be validated. Anyway, I am not sure about the variables that you are using. Let me to explain. To use the "DateValid" action, for example, we need to pass a "Date variable" to the action, not the input's value, but a date variable created with "NewDate".

So step by step. Take a look at the DateInput sample app. You can see how we deal with a date input. First of all, what we do is to use the date input value with the NewDate action. So we can then validate that date, increment that date, etc. Probably this can be the way if you finally decide to use the date input: just follow the sample, get a Date variable from the input, and then validate that Date variable with the "DateValid" action.

The date input has no time capabilies, there is a "time" input, not already implemented in AB, probably because their "no very well proved capabilities": differences between browsers, etc. Probably here is algo better to use a couple inputs: one for the hour and other for the minutes. Try with I mention in this post, and we can go ahead if needed, since, of course, we can use also some possible additional Javascript code.



DecSoft

Hello again,

I forget something important:

The user input must be validated in the client side, of course, but, also in the server side: all the user input must be validated in both client and server side.


DecSoft

Hello again,

Note something, Ryan: If you try the DateInput sample in the internal debugger browser, you can change the value of the input to "aaaaa", for example, however, if you use the input value with the "NewDate", and then you use the "DateValid" action, you can see that the date continue to be valid... why? This is one of the particularities of this control: the browser show one value "aaaaa", but, since is not valid, don't change the real value of the input, which continue to be the previous date.

But you can't reproduce that behaviour in Mozilla Firefox and other modern browsers, because these browsers don't allow to the user to put something like "aaaaa" in an input control. Probably the date input can be good here in these browsers (and also in platforms like Android) because the date is always valid: because the browsers don't allow the user to put anything than a date in the input, so, may we can then validate if the input is "before" or "after" some date, but, not if is a valid date variable, because always is a valid date variable. So take this in consideration to continue your research.



Ryan Sytsma

Thank you David. I think I will break apart the date values and time values into Select controls. It seems like data entry would be faster and I can be strict with formats in the background.



DecSoft

Hello Ryan,

The use of separated select or inputs can be good to avoid the date input, however, note what I mention in my latest post: if you avoid Internet Explorer 11 (and other "older" browsers), and probably you can avoid it at all... you can probably use the date input, because what I mention: the browsers don't allow the user to put other thing than a date, so, we can always have a date... and with the help of the "NewDate" (see my above posts around the DateInput sample app, you must try this) and the other related date actions like "DateValid", we can probably validate the date as we wanted.

Just made some tests, Ryan, and, if you have any further question about, don't hesitate to post it here.



Ryan Sytsma
This app will only be deployed to Android as an .apk

DecSoft

Hello Ryan,

Then, in your case, I will try the date input, even when I already implement in certain app (Android too, but also iOS), the usage of different selects with good results. So maybe I just confuse you with my firstly words... yes... the date input can have some kind of problems like the related ones, however, in your specific case, probably is the best control to use, from the user point of view (it's difficult to not insists that the different selects can be good also).

Go ahead, Ryan, try with the date input, try to validate as you wanted, and, if you find some specific problem, post it here and we will try to help you... or... as you wanted... use the different selects inputs... just as you wanted. Try both things... and see what can be better for you: I already told you how to deal with the date input value: pass to the "NewDate" action, so you get a date variable ready to be used in other date related actions, like "ValidDate".


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.