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

can you please send some test cases and screenshot of error message.

what I have tested is 123 SAR , 234.33 SAR

 

Vishal Birajdar
ServiceNow Developer

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

sony8_0-1693987059766.png

The below is the error not even accepting numeric

as you want it to be currency specific regex should contain "SAR" in the variable.

Can you try with these test cases it should work

 

e.g., 400 SAR , 567.78 SAR

Vishal Birajdar
ServiceNow Developer

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