How to limit value or length of number field?
How to limit value or length of number field?
altracka
Posts: 9Questions: 6Answers: 0
I would like to limit a number field to a reasonably small value. I would prefer to limit the value to 1000, but would also be happy to limit the length to 3. maxlength works if the type is text, but it has no effect if the type is number- it lets me type any length of input, for example 9999999999.
var editor = new $.fn.dataTable.Editor({
table: containerId,
display: 'bootstrap',
fields: [
{ label: 'good', attr: { maxlength: 3 } },
{ label: 'bad', attr: { type: "number", maxlength: 3 } },
],
});
Answers
Just use a validator on the server.
You you can also do client side validation if you prefer that:
https://editor.datatables.net/examples/api/clientValidation.html
See also this SO thread which notes that
maxlength
is ignored by the browser fortype=number
.Allan