Reputation: 73988
I need to make validation pass only for integer value in a NumberTextBox
.
Using the following code, entering a decimal value in the NumberTextBox
54.454 wrongly validates.
I would like to know:
integer
values?.
?https://jsfiddle.net/9Lh3p0fb/7/
require(["dijit/form/NumberTextBox", "dojo/domReady!"], function(NumberTextBox){
new NumberTextBox({
name: "programmatic",
constraints: {pattern: '@@@'}
}, "programmatic").startup();
});
Upvotes: 2
Views: 1388
Reputation: 462
I got a code from here and modified . please check if it solves your problem.
<input type='text' onkeypress='validate(event)' />
<script type="text/javascript">
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]/;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>`
Upvotes: 0
Reputation: 16615
You can use places: 0
as a configuration option:
require(["dijit/form/NumberTextBox", "dojo/domReady!"], function (NumberTextBox) {
new NumberTextBox({
name: "programmatic",
constraints: {
pattern: '@@@',
places: 0
}
}, "programmatic").startup();
});
Upvotes: 1