Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Decimal point validation in catalog variable

armanoj
Mega Sage

Hi Team,

 

In catalog variable field i need validation decimal point only 2 digit allow

eg

10.22

10.01

 

invalid

10.233

1.001

 

how to create this validation

 

 

 

1 ACCEPTED SOLUTION

Viraj Hudlikar
Tera Sage

Hello @armanoj 

 

You can create a variable validation regex and use for your variable.
First open this module as showcased below:

VirajHudlikar_0-1762615252307.png

 

Create a new record and provide your desired regex as showcased below:

VirajHudlikar_1-1762615310253.png

Regex code:

^\d+(\.\d{1,2})?$

 

Now use this over your catalog variable created as showcased below:

VirajHudlikar_2-1762615452578.png

 


Below is working of regex over portal with +ve and -ve test case.

VirajHudlikar_3-1762615524656.pngVirajHudlikar_4-1762615541905.pngVirajHudlikar_5-1762615559033.pngVirajHudlikar_6-1762615583343.pngVirajHudlikar_7-1762615604499.pngVirajHudlikar_8-1762615617924.pngVirajHudlikar_9-1762615631207.pngVirajHudlikar_10-1762615645074.png

 

 

If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

View solution in original post

4 REPLIES 4

Viraj Hudlikar
Tera Sage

Hello @armanoj 

 

You can create a variable validation regex and use for your variable.
First open this module as showcased below:

VirajHudlikar_0-1762615252307.png

 

Create a new record and provide your desired regex as showcased below:

VirajHudlikar_1-1762615310253.png

Regex code:

^\d+(\.\d{1,2})?$

 

Now use this over your catalog variable created as showcased below:

VirajHudlikar_2-1762615452578.png

 


Below is working of regex over portal with +ve and -ve test case.

VirajHudlikar_3-1762615524656.pngVirajHudlikar_4-1762615541905.pngVirajHudlikar_5-1762615559033.pngVirajHudlikar_6-1762615583343.pngVirajHudlikar_7-1762615604499.pngVirajHudlikar_8-1762615617924.pngVirajHudlikar_9-1762615631207.pngVirajHudlikar_10-1762615645074.png

 

 

If my response has helped you, hit the helpful button, and if your concern is solved, do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Great Thanks

Helpful! Thanks

 

Sarthak Kashyap
Mega Sage

Hi @armanoj ,

 

I tried your problem it worked for me please check solution below 

I created a variable called "Number" and added a OnChange Client Script on that variable please check below code 

alert("Here called = " + newValue);
   var regex = /^\d+(\.\d{1,2})?$/;

    if (!regex.test(newValue)) {
		alert("Please enter a valid number with up to 2 decimal places (e.g. 10.22).");
        g_form.showFieldMsg('u_score', 'Please enter a valid number with up to 2 decimal places (e.g. 10.22).', 'error');
        g_form.setValue('u_score', ''); 
    }

SarthakKashyap_1-1762616924459.png

 

 

Result:

 

SarthakKashyap_0-1762616851148.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,
Sarthak