Question
HCL Technologies Ltd
IN
Last activity: 30 Nov 2019 0:02 EST
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)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
HCL Technologies Ltd
IN
Any Solution?
Pegasystems Inc.
IN
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.
HCL Technologies Ltd
IN
I tried as you said, But it's not working still allowing after 2 decimal values.
Coforge DPA
GB
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
HCL Technologies Ltd
IN
I tried with Edit-Input also but not working.
I referred Edit-Input rule in advance tab of property.
I am using 7.2.2 Version.
BPM Company
NL
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"
HCL Technologies Ltd
IN
Hi Vaspoz,
it's not working still allowing more than 2 decimal points.
BPM Company
NL
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"
CommonWealth Bank of Australia
IN
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,
HCL Technologies Ltd
IN
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
Pegasystems Inc.
IN
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>