Regex for decimal validation

Bharati Mhatarm
Tera Contributor

I have created SingleLineText Field on Record Producer name as Temperature. I Want to achieve to validate this field from regex  which takes only integer and with 2 decimal digits. And also it takes a value within a range from  95.0 to 106.0.

If the entered temperature is not within this range display Please enter a valid temperature in the range of 95.0 – 106.0 degrees Fahrenheit.

Ex., If the user enters 95 only it should take value. And also it should take up to 106.0

Thank you

4 REPLIES 4

Rupali1
Tera Contributor

Hii Bharati,

  You can write below script  to achieve numbers only 

   

function onChange(control, oldValue, newValue, isLoading) {

 

  if (isLoading || newValue == '') {

 

  return;

 

  }

 

  var regexp = /^[+]?\d*$/;

 

  if(!regexp.test(newValue)){

 

  alert('Please enter numeric value');

 

  g_form.setValue('v_sec_review_unknown','');

 

  }

 

}

 

Please mark it as helpful or correct if it helps you.

 

 

Thanks ,

Rupali Bondar

 

 

Hi,

Please use below script:


if (isLoading || newValue == '') {
  return;
  }
  var regexp = "^(?:106(?:\.0)?|[95-105](?:\.[0-9])?|0?\.[1-9])$";
  if(!regexp.test(newValue)){
  alert('Please enter numeric value');
  g_form.setValue('v_sec_review_unknown','');
  }
}

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Bharati Mhatarm
Tera Contributor

Thank you!, I want to achieve a number with 2 decimal

Priyanka SHIND2
Mega Guru

Hello,

Could you try the below expression it will be allowed you to enter max 2 decimal places 

^\d+\.\d{0,2}$
//where "2" is the maximum allowed decimal places.

Check below links for your refernece
https://stackoverflow.com/questions/4690986/regex-needed-to-match-number-to-exactly-two-decimal-places
https://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2/308216
https://forums.asp.net/t/1909870.aspx?Regular+expression+to+allow+a+number+upto+2+decimal+places

Pelase mark my answer correct or helpful if it helped you in any way.

Thank you