This example demonstrates how to allow entering only numbers in dxNumberBox. For this task we need to handle the dxNumberBox.onKeyPress event and check whether the typed symbol is a number. If this is not a number, prevent the default action of the event by calling the preventDefault method of the event object that is passed to the onKeyPress event handler.
See also:
JavaScript RegExp
Question Comments
Added By: CM Tee at: 6/18/2015 9:06:10 PM
hi, the syntax on view got error during runtime,
<div class="dx-field-value">
<div data-bind="dxNumberBox: integerSettings { value: qty, min: 1 }"></div>
</div>
please help.
Added By: Alex Skorkin (DevExpress Support) at: 6/19/2015 1:20:53 AMHello Jerry,
To process your recent post more efficiently, I created a separate ticket on your behalf: T257499: The syntax for dxNumberBox interger values got error during runtime. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
Hi Jake,
Thank you for bringing this to our attention. I've updated our example. My changes will be synced a bit later.
Added By: Coco panuncio at: 11/6/2018 6:42:43 AM hello I am trying to run this example online but i don't think it is working because on the integer i can still input decimals. Any ideas of why?Thanks!
Coco Added By: Coco panuncio at: 11/6/2018 6:48:11 AM I see what the problem is, i downloaded the code and the code had the following:
[JavaScript]$("#integerContainer").dxNumberBox({ valueChangeEvent: "keyup", onkeyPress: function(e){//this function name is not with the right casing "onKeyPress"var event = e.jQueryEvent, str = String.fromCharCode(event.keyCode);if(!/[0-9]/.test(str)) event.preventDefault();}});