本文介绍了Javascript验证在Windows和Android手机上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为名字"实现了Java脚本验证,该名字仅接受字符.它可以在计算机和Iphone上正常工作,但是如果我在其他手机上检查它,它也可以接受数字.我该怎么办?
我正在使用以下代码
在此先感谢
I have implemented java script validation for "first name" which accepts character only. It''s working proper on computer and Iphone but if I a checking It on other mobile It''s accept numbers also. What should I do for this problem?
I am using following code
Thanks In Advance
var alpha = "[ A-Za-z]";
var numeric = "[0-9]";
var alphanumeric = "[ A-Za-z0-9]";
function onKeyValidate(e,charVal){
var keynum;
var keyChars = /[\x00\x08]/;
var validChars = new RegExp(charVal);
if(window.event)
{
keynum = e.keyCode;
}
else if(e.which)
{
keynum = e.which;
}
var keychar = String.fromCharCode(keynum);
if (!validChars.test(keychar) && !keyChars.test(keychar)) {
return false
} else{
return keychar;
}
}
<input type="text" value="" name="first_name" id="first_name" placeholder="First Name" onkeypress="return onKeyValidate(event,alpha);"/>
我尝试过的事情:
我在上面的代码中尝试过此代码,请帮助我
What I have tried:
I tried this above code please help me
推荐答案
这篇关于Javascript验证在Windows和Android手机上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!