问题描述:

I used the below code to validate mobile number:

function lfnCheckMob(e) {

var key1 = e.keyCode;

if (key1 == 8 || key1 == 9 || key1 == 46 || (key1 >= 35 && key1 <= 40)) { return true; }

if (e.shiftKey || e.ctrlKey || e.altKey) {

e.preventDefault();

}

else {

var key = e.keyCode;

if (!((key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {

e.stopPropagation();

e.preventDefault();

}

}

}

It works fine on desktop browsers. But when I try it on a browser on smartphone, it allows special characters like &, @.

I tried putting alert to see the keycode value on phone, its showing keycode 0 for all the keys.

Can someone please help me for this?

网友答案:

Either go with 1

<input type="number" step="1" />

OR

<input type="text" pattern="\d*" />

And for more information, use link

相关阅读:
Top