简体   繁体   English

智能手机浏览器上的手机号码验证

[英]Mobile number validation on smart phone browser

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. 我尝试设置警报以查看电话上的键值,该键显示所有键的键代码0。 Can someone please help me for this? 有人可以帮我吗?

Either go with 1 要么去1

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

OR 要么

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

And for more information, use link 有关更多信息,请使用链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM