Regex to accept numbers and can only accept one dot for decimals.

pardhiv
Tera Contributor

I am trying to write a regex with on change client and tried the below. It needs to accept numbers as below

 

ex: (should accept numbers and dots)

 

12345

12345.67

12345.678xxx (No limitation on decimals unless its not possible)

 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   //Accept numbers with only dots
   var pattern =  /^(([0-9.]?)*)+$/;  
    if (!pattern.test(newValue)) {
		g_form.clearValue('u_amount');
        g_form.showFieldMsg('u_amount', 'Accepted format : 354621.32', 'error', true);
        
    } 
   
}

 

 

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@pardhiv What is the issue here, your regex is working accepting number and dot. Is it not working in client script?

It isn't accepting both the inputs I gave in the question.  I don't have any limitation on number of decimal places. If there is no option , I can stick with 2 places

@pardhiv I tested on my PDI and it is just working fine for me with both the inputs 1234 and 1234.12.

Screenshot 2024-06-12 at 12.16.22 AM.pngScreenshot 2024-06-12 at 12.16.13 AM.pngScreenshot 2024-06-12 at 12.17.07 AM.png

 

Please clear your cache of the browser and then check as the script is working just fine.

Seems like the Issue is with my client script , I tried multiple regex and they been clearing out values.