validate time field (no date)

  • 1 December 2017
  • 8 replies
  • 54 views

Userlevel 3
Badge +8

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


8 replies

Userlevel 5
Badge +14

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?

Userlevel 3
Badge +8

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

Badge +8

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

Userlevel 3
Badge +8

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

Badge +8

‌ 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. 

Userlevel 3
Badge +12

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.

Userlevel 3
Badge +8

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

Kassie

Userlevel 5
Badge +14

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

211264_pastedImage_1.png

211275_pastedImage_3.png

211274_pastedImage_2.png

details on controls used

input boxes

211276_pastedImage_4.png

'Value' calculated value controls

211277_pastedImage_5.png

'typeof(value)' calculated controls

211278_pastedImage_6.png

comparison calculated value controls

211279_pastedImage_7.png

211280_pastedImage_8.png

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?

Reply