- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 02:30 PM
Hello everyone,
I need some assistance with updating regex on a field for my catalog item, this field functions as a time field and i want users to be able to enter time zones after the ex. 12:30 PM EST or 11:20 PM ACDT, my regex below is allowing for anything to be entered into the field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('time');
var str = newValue; //the newValue comes from the onChange function's parameters
var pattern = new RegExp(/\b(0?\d|1[0-2]):[0-5]\d(\s)?([AaPp][Mm]$)/([A-z])).test(str); //checks for 1:23:45 or 01:23:45
if (!pattern) {
g_form.showFieldMsg('time','Please use the right format.','error');
return pattern;
} else {
g_form.hideAllFieldMsgs();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 07:17 PM - edited 07-29-2023 07:42 PM
Try this pattern ^\d{1,2}:\d{2}(?:am|pm)?\s+[A-Z]{2,4}$
it should only match inputs where a time is followed by a time zone (time zone in upper case) eg 12:30pm EST or 10:30am PST
how are you determining if the time zone is correct?
Mark ✅Correct if this solves your issue and also mark 👍Helpful if you find my response helped in any way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 07:17 PM - edited 07-29-2023 07:42 PM
Try this pattern ^\d{1,2}:\d{2}(?:am|pm)?\s+[A-Z]{2,4}$
it should only match inputs where a time is followed by a time zone (time zone in upper case) eg 12:30pm EST or 10:30am PST
how are you determining if the time zone is correct?
Mark ✅Correct if this solves your issue and also mark 👍Helpful if you find my response helped in any way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 03:12 PM
@DanielCordick hmmm good question, i am not currently checking the time zone for accuracy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 10:52 AM
Did you test out the pattern? Did it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:05 AM
I did test it out, it works, really appreciate you responding.