- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:15 AM
Hi,
I have a decimal field where i want to give out an alert message when the number entered has more than 3 decimal places i.e. if the input for a decimal field is 13.4567, i want an alert message to pop up
Can regex validation be done on a decimal field?
PFB the onchange script (for the decimal field) i wrote which isn't working, any modifications to this?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var countDecimals = function(value) {
if (Math.floor(value) !== value)
return value.toString().split(".")[1].length || 0;
return 0;
}
alert(newValue);
if (countDecimals(newValue) != '2') {
alert('should have 2 decimal places');
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:30 AM
Hi,
Here is sample script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sdVal=g_form.getValue('short_description');
var splitVal=sdVal.split('.');
alert("First = "+splitVal[0]+"second = "+splitVal[1]);
var len=splitVal[1].length;
alert(len);
if(len>3){
alert('wrong decimal value');
}
else{
alert('correct decimal value');
}
}
Note - Make changes accordingly as per need.
Mark correct/helpful based on impact.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:30 AM
Hi,
Here is sample script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sdVal=g_form.getValue('short_description');
var splitVal=sdVal.split('.');
alert("First = "+splitVal[0]+"second = "+splitVal[1]);
var len=splitVal[1].length;
alert(len);
if(len>3){
alert('wrong decimal value');
}
else{
alert('correct decimal value');
}
}
Note - Make changes accordingly as per need.
Mark correct/helpful based on impact.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 03:28 AM
Thanks!