cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

validate time field (no date)

Hey everyone,

I want to validate a time field that's is actually a single line of text field with a time formatting regex for validation. I want to make sure the start time is prior to the end time. Any ideas on how to accomplish this?

Wouldn't it be nice if you could select time only for a date/time field in SharePoint?

Thanks

Kassie

Reply
8 Replies
Workflow Hero

Re: validate time field (no date)

could you post a sample how does your time inputs might look like?

will it just single number like '13' (hours) or can it be like "13:15" (hours:minutes)?

is the dropdown intended to be AM/PM selector?

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

Hey Marian!

Yes, my current regex validates the time is HH:MM format and the dropdowns are AM/PM. So far the HH:MM validation works great but I'm not sure how to make sure they don't add a start time that's after the end time.

Honestly, I feel like the users should be able to figure it out on their own, and if it's not correct, it's probably just an miss-type. Once the form is submitted, it adds the event to a calendar so it would cause issues if they do mess it up.

Thanks for your help!

Kassie

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

Any chance you could use military time? Then you could use number fields and the math would be simple.

Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

Probably no to the military time.  That would be an excellent fix though!

Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

‌ Maybe this link would help. It discusses creating a second column based on the first one that displays only the time.

Display time only in the date field column. 

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

Hi,

If you can add few line of jquery to your Nintex, you can follow this approach.

1. Create 2 date & time columns in list for this, BeginDate, EndDate are your column names, and set their default date value to "Today".

2. Drag them on your form and name them, ctrlBeginDate, ctrlEndDate.

3. Use the below script in form settings to hide date portion of both controls.

      

NWF$(document).ready(function () {

NWF$('#' + ctrlBeginDate).next('img').hide();
NWF$('#' + ctrlBeginDate).hide();
NWF$('#' + ctrlEndDate).next('img').hide();
NWF$('#' + ctrlEndDate).hide();

});

4. Create a rule for comparing time (the both controls will have the default date set to "today", so, the comparison will be BeginDate's control date&time and EndDate's control date&time). And ignore the stroked out portion, that is not required in your requirement.

 

5. Form at run time will be shown as below.

Thanks,

Krishna.

Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

I'll give it a try and let you know! Thanks ‌!

Kassie

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: validate time field (no date)

does the time input have to be split to two fields?

if you could make it single filed, and if time is always entered in the same format as defined by current user's locale the the validation could be as simple as comparing control1 < control2

maybe it's not obvious, but you can take advantage of (sometimes pleasant, sometimes unpleasant) 'feature' that nintex tries to 'understand' values entered in (some) controls and convert it to a datatype/object that they resemble to.

in your case it means that if time input control is populated with a value that fits to time format defined by current user locale, nintex automatically converts it to Date object(s) which could be directly compared.

see following exercise

details on controls used

input boxes

'Value' calculated value controls

'typeof(value)' calculated controls

comparison calculated value controls

BUT, if you are going to use time inputs to make a calendar event anyway, I wouldn't complicated things on both ends, and used (and strongly recommended to use) regular date controls.

besides of input validation problems, guessing to what date (day) times are related to when creating calendar event, consider as well situations when eg. an item will be created shortly before midnight and workflow (calendar event creation) will take its turn after midnight.

or, if workflow fails or need to be rerun the other day.

how in these scenarios will you identify correct date, the time is related to?

Accept as Solution Reply