itsm

karthik65
Tera Guru

Hi All,

I have a field for frequency in catalog item to update it in Custom Table.

This field should be 234.234 format. how can i restrict it in Client Script. 

Below is my Client Script.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below

   var reg = /^[0-9]*\.[0-9]\d{3}$/;
    var ans = g_form.getValue('frequency_number_u');
   
    if(!reg.test(ans))
    {
        alert('Please enter a valid value.');
        g_form.clearValue('frequency_number_u');
    }
 
}
1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

Hi @karthik65 ,

 

Use below script, i have tested it, working fine. it will accept 3 digit before and after decimal. If you before digit can be anything then use :var reg = /^\d+\.\d{3}$/;

var reg = /^\d{3}\.\d{3}$/;
    var ans = g_form.getValue('frequency_number_u');
   
    if(!reg.test(ans))
    {
        alert('Please enter a valid value.');
        g_form.clearValue('frequency_number_u');
    }

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

5 REPLIES 5

How can i set decimal for a frequency field after three numbers?