Allow only numeric in input

QuestionsAllow only numeric in input
Anonymous asked 5 years ago

What the $col option to only allow a user to enter digits? One of my fields is a varchar but I don’t want the user to be able to enter anything other than digits.

1 Answers
Abu answered 5 years ago

Try following:

1) Builtin JS validation onsubmit: http://www.phpgrid.org/docs/validation/#js-validation
$col[“editrules”] = array(“number”=>true);

2) Using oninput JS callback:
$col = array();
$col[“title”] = “Total”;
$col[“name”] = “freight”;
$col[“width”] = “170”;
$col[“editoptions”][“oninput”] = “this.value = this.value.replace(/[^0-9.]/g, ”).replace(/(\..*)\./g, ‘$1’);”;

3) You can also use custom client side validation using:
http://www.phpgrid.org/docs/validation/#custom-js-validation
and get regex from
https://stackoverflow.com/questions/469357/html-text-input-allow-only-numeric-input

Your Answer

3 + 16 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?