Duration type field should accept only numeric value

yamini9
Giga Contributor

Hi ,

 

Currently time_worked field is accepting alphabets with including numeric value but as per the requirement it should not accept alphabets and special characters . Can anyone help me on this requirement. Thanks in advance.

 

Time worked field type is "Duration".

 

yamini9_0-1690370169764.png

i have written onchange client script as below

 

var numericRegex = /^[0-9].*/;
var numnericVal = g_form.getValue('time_worked');
if (!numericRegex.test(numnericVal)) {
alert("Please enter numeric values");
g_form.setValue('time_worked', ''); 
}

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@yamini9 

it's OOB filed so ideally it should not accept characters.

Did you check any OOB script exists to handle this validation for any OOB field?

The same you can replicate for your field

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Thanks for quick reply

I have tried as per knowledge but i didn't get it.

Can you please suggest any OOB script which handles this validation.

Awaiting for your reply.

Thanks 

Hi Ankur,

Thanks for quick reply,

I tried from my end but i didn't find it.

Can you suggest me any OOB script if you find.

Awaiting for reply.

 

Thanks 

@yamini9 

Seems platform bug I checked by applying the same on OOB duration field.

It seems g_form.getValue() doesn't work on duration field

Check this link. I was unable to open it

https://hishowcase.service-now.com/kb?id=kb_article_view&sysparm_article=KB0752390 

AnkurBawiskar_0-1690430620429.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader