如何用正则表达式编写JavaScript函数来区分字符串是汉字还是拼音?
- 内容介绍
- 文章标签
- 相关推荐
本文共计90个文字,预计阅读时间需要1分钟。
复制代码+代码如下:javascriptfunction checkFormat(str) { if (escape(str).indexOf(%u) !=-1) { alert(不能含有汉字); } else if (str.match(/\\/) !=null) { alert('不能含有特殊字符'); }}
复制代码 代码如下:function checkFormat(str)
{
if (escape(str).indexOf("%u")!=-1)
alert("不能含有汉字");
else if(str.match(/\D/)!=null)
{
alert('不能含有字母');
}
}
本文共计90个文字,预计阅读时间需要1分钟。
复制代码+代码如下:javascriptfunction checkFormat(str) { if (escape(str).indexOf(%u) !=-1) { alert(不能含有汉字); } else if (str.match(/\\/) !=null) { alert('不能含有特殊字符'); }}
复制代码 代码如下:function checkFormat(str)
{
if (escape(str).indexOf("%u")!=-1)
alert("不能含有汉字");
else if(str.match(/\D/)!=null)
{
alert('不能含有字母');
}
}

