Jquery验证:仅允许使用字母和空格。 [英] Jquery Validation: allow only alphabets and spaces.

查看:93
本文介绍了Jquery验证:仅允许使用字母和空格。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

 



 $(' #textName')。keypress(function(e){
var regex = new RegExp( ^ [a-zA-Z] + $);
var str = String .fromCharCode(!e.charCode?e.which:e.charCode);
if (regex.test(str)){
返回 true ;
}
else
{
e.preventDefault();
alert(' 请输入Alphabate');
return false < /跨度>;
}
});

解决方案

' #textName')。keypress(function(e){
var regex = < span class =code-keyword> new RegExp( ^ [a-zA-Z] +


);
var str = String .fromCharCode(!e.charCode?e.which:e.charCode);
if (regex.test(str)){
返回 true ;
}
else
{
e.preventDefault();
alert(' 请输入Alphabate');
return false ;
}
});


试试这个:

 ^ [a -Za-Z\s] + 

I have this code:


$('#textName').keypress(function (e) {
        var regex = new RegExp("^[a-zA-Z]+$");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        }
        else
        {
        e.preventDefault();
        alert('Please Enter Alphabate');
        return false;
        }
    });

解决方案

('#textName').keypress(function (e) { var regex = new RegExp("^[a-zA-Z]+


"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } else { e.preventDefault(); alert('Please Enter Alphabate'); return false; } });


Try this:

^[a-zA-Z\s]+


这篇关于Jquery验证:仅允许使用字母和空格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆