Need help for custom variable validation in Catalog client script Service Portal

sony8
Tera Contributor

I have below requirement.

 

there is variable name Estimated Cost 

Type : it should be upto 2 decimal places or numeric and need to show in SAR currency.

 

written below code for decimal and numeric checking but how to add currency in Variable??

 var decimalRegex = /^\d*(\.\d{1,2})?$/;
    g_form.hideFieldMsg('estimated_cost', true);

    if (!decimalRegex.test(g_form.getValue('estimated_cost'))) {
        g_form.showFieldMsg('estimated_cost', 'Estimated cost must be a numeric or decimal value.', 'error');
    }

 

Thank you

 

7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

Hi @sony8 

you could extend the regular expression to:

 

var decimalRegex = /^\d*(\.\d{1,2})? (SAR|SR)$/;

 

 

You can test this at https://regex101.com/r/kyz4N5/1 

Maik

@Maik Skoddow  when i add above Regex it was showing error for every value i enter in Estimated Cost Variable.

Is there any other way??/

Vishal Birajdar
Giga Sage

Hi Sony,

 

Can you try this :

 

^\d+(?:\.\d{1,2})?\s*SAR$ 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

@Vishal Birajdar  same field message error is coming