Copy link to clipboard
Copied
I'm trying to find a keystroke validation for numbers where commas and decimals (0.000) may be entered. Any help would be appreciated.
Copy link to clipboard
Copied
Allow only numbers, commas and dots.
event.rc = /^[0-9,.]*$/.test(event.change);
Copy link to clipboard
Copied
Why not use one of the built-in options under the Format tab?
Copy link to clipboard
Copied
I would like for the user to be able to enter 100 or 0.100
Copy link to clipboard
Copied
Yes, they can do that with those settings...
Copy link to clipboard
Copied
If I select number to 3 decimal places it changes 100 to 100.000. If I select 0 decimal places, it doesn't allow 0.100
Copy link to clipboard
Copied
Hi,
Here is a custom keystroke script that allows your request.
if(!event.willCommit) {
var aTester=event.value.split("");
aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
var testeChaine=aTester.join("");
var numberRegEx=/^(\d+(.\d{0,3})?)?$/;
event.rc=numberRegEx.test(testeChaine);
} else {
var numberRegEx=/^\d+(.\d{1,3})?$/;
event.rc=event.value=="" || numberRegEx.test(event.value);
}
With this script, if you enter a dot you can add up to 3 digits after. You can modify it to allow the number of digits you wish.
@+
Copy link to clipboard
Copied
I see what you mean. In that case, no, the built-in Number format setting will not work for you.
You were given some good options below, though.