Regex: maximum 0 to 8 not allowed moret han 8.1

chandan31
Tera Contributor

Hi All,

 

I have developed regex :^[0-8,\,]+([\.][0-9]{0,1}+)?$:- in this regex it allowing  0 to 8 with one decimal number like 7.8. 8.1 , 8.9. But it should be max  8.0 after that it should through the error (example : 8.1, 8.9 through error  ). Can you help me to redevelop the regex.

 

Thanks ,
chandan

1 ACCEPTED SOLUTION

SAI VENKATESH
Tera Sage
Tera Sage

Hi @chandan31 

You can try the below script in onchange client script

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

    if (!newValue.match(/^(?:[0-7](?:\.[0-9])?|8(?:\.0)?)$/)) {
        alert("he value must be between 0 and 8, with at most one decimal place, and the maximum value allowed is 8.0");
		g_form.clearValue('number')
    }

   //Type appropriate comment here, and begin script below
   
}

 

 

Thanks and Regards

Sai Venkatesh

View solution in original post

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

Hi @chandan31 try the below

^[0-8]$|^[0-7]\.\d+$|^8\.0$

Regards
Harish

HI  Harish,

 

It should allow maximum one decimal number like 7.8,6.7 or 3.2.

SAI VENKATESH
Tera Sage
Tera Sage

Hi @chandan31 

You can try the below script in onchange client script

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

    if (!newValue.match(/^(?:[0-7](?:\.[0-9])?|8(?:\.0)?)$/)) {
        alert("he value must be between 0 and 8, with at most one decimal place, and the maximum value allowed is 8.0");
		g_form.clearValue('number')
    }

   //Type appropriate comment here, and begin script below
   
}

 

 

Thanks and Regards

Sai Venkatesh

SK Chand Basha
Giga Sage

Hi @chandan31 

 

^(?:[0-7](?:\.\d)?|8(?:\.[0-9])?)$

 

Can you check with this .

 

Mark it Helpful and Accept Solution!! If this helps you to understand .