I need to restrict a text box to 2 decimals
Hi,
I need to restrict a text box to 2 decimals (For ex; User should not be able to enter after 2.12)
Thanks,
Ravi
***Moderator Edit-Vidyaranjan: Updated Platform Capability***
-
Like (0)
-
Please try the below workaround:
1. Open the "UserWorkForm" and add the below script.
<script>
$('#Test').on('input', function () {
this.value = this.value.match(/^\d+\.?\d{0,2}/);
});
</script>
2. In the place of "Test" you should add the element id of your property. You can find that using browser debugger tool.
Hi
Can you try with an Edit-Input rule with below code:
---------------------------------------------------------------------
String input1,input2; if(theValue.contains(".")){ input1 = theValue.substring(theValue.indexOf("."),theValue.length()); if(input1.length()>2){ theValue = theValue.substring(0,theValue.indexOf(".")+3); } if(input1.length()==2){ theValue = theValue+"0"; } if(input1.length()==0){ theValue = theValue+"00"; } } else{ if(theValue.length()!=0){ theValue = theValue+".00"; } }
----------------------------------------------------------------
Regards
Bhavya
Try to use this edit validate:
if (theValue.contains(".")) {
String[] str = theValue.split("//.");
theValue = str[0] + "." + str[1].substring(0, 2);
}
And on the control, add an event "On Change" with action "Post Value"
Sorry, not exactly correct solution =\
here's the right one (just tested on 7.3.1):
if (theValue.contains(".")) {
String[] str = theValue.split("\\.");
if (str.length == 2) {
int size = str[1].length() > 2 ? 2 : str[1].length();
theValue = str[0] + "." + str[1].substring(0, size);
}
}
Plus, the action should be not "Change" but "Any Key"

Hi,
In the text input cell properties, on the Presentation tab, you can set the read only format as number and can set the number of decimal places.
Is there any business requirement that you should use only Text input?
If not you can directly use Decimal control in which you can restrict the number of decimal values on parameters tab.
Thanks,

Hi Mutha,
I am using decimal control only now, but my requirement is user should not enter more than 2 decimal points.
Ex:- 12.99876 User should not enter after 12.99
Hi Ravi,
Thanks for posting the query. Can you try the below javascirpt code check it if is restricting 2 decimals
<script type="text/javascript"> if(document.getElementById("Prop") !=null){ document.getElementById("Prop").onkeypress = function(event){ var charCode = document.getElementById("Prop").value.toString(); if(charCode.includes(".")){ var numb = charCode.split(".")[1]; if(numb!=null && numb.length>1) { alert("Only 2 decimal places allowed"); return false; } } }; } </script>