text box to only accept numbers

0
Hi I am using a text box to enter mobile number. i know how to provide validation to give only numbers. but what i want is, the textbox should not allow user to enter string values means that alphabets should not work on that text box when i try to type them. Is it possible ? 
asked
3 answers
2

In case anyone is looking for a solution to the above question: you can use html/javascript snippet and add a class to the desired textbox and use the same class to listen to the keypress event and suppress any key other than numbers as below:

$(".phone").keypress(function (event) {
  var keycode = event.keyCode ? event.keyCode : event.which;
  if (keycode < 48 ||  keycode > 57) {
    return false;
  }
});

Full list of keycodes can be found on google! 

Hope this helps.

answered
0

Hi Shaan,

Please check if input mask is what you're looking for.

https://docs.mendix.com/refguide/text-box#2-8-2-input-mask 

answered
0

Hi Shaan Ahmed,

Why not just try a regex to allow only numbers and use isMatch to validate and give feedback ? I think this is the easiest and smartest way to do it.

Regex: 

^[0-9]*$

Regards,

Sharad R K

answered