不允许用户输入全角字母数字

由用户会输入全角字符,给查询带来不便,所以需要限制用户输入全角字符。

<INPUT name="CardId" onKeyUp="quanjiao(this);">
<script language="javascript">
function quanjiao(obj)
{
    var str=obj.value;
    if (str.length>0)
    {
        for (var i = str.length-1; i >= 0; i--)
        {
            unicode=str.charCodeAt(i);
            if (unicode>65280 && unicode<65375)
            {
                alert("不能输入全角字符,请输入半角字符");
                obj.value=str.substr(0,i);
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/easyboot/article/details/82802873
今日推荐