Is there an easy way to force users to enter numbers only in a Xpages editbox? Other than validating the field after the fact that is. I don't want them to be able to enter a number at all.
Asked
Active
Viewed 1,167 times
4 Answers
4
You can add client-side Javascript handling such as what has been suggested here: HTML Text Input allow only Numeric input

Community
- 1
- 1

Per Henrik Lausten
- 21,331
- 3
- 29
- 76
1
You write below code in a Xpages editbox on event onkeypress
if (event.keyCode >= 48 && event.keyCode <= 57)
{
event.returnValue = true;
}
else
{
event.returnValue = false;
}
This code will force user to enter numbers only.

Sergey Glotov
- 20,200
- 11
- 84
- 98

YOGI
- 50
- 5
1
You can add validation and formatting of numbers using the built in dojo.number class: http://dojotoolkit.org/api/1.6/dojo/number/format and make use of the dojo.form widgets.
If you're running on a mobile web platform (iOS or Android) then you should also think about setting the type of the field to number so that the platform itself will add another level of protection.
Matt

Matt White
- 700
- 4
- 14