当前位置: 代码迷 >> 跨浏览器开发 >> 正则表达式,该怎么解决
  详细解决方案

正则表达式,该怎么解决

热度:7991   发布时间:2013-02-26 00:00:00.0
正则表达式
如何用正则表达式判断一个变量是否是字符串类型的

------解决方案--------------------------------------------------------
JScript code
var regex = /[^\d]+/;var arr = ["1","2","3","a","b","c","a1","2b2"];for(o in arr){    var bool = regex.test(arr[o]);    document.write(arr[o]+"-"+bool+"<br/>");}
------解决方案--------------------------------------------------------
var regex = /[^\d]+/;
var arr = ["1","2","31111a","a","b","c","a1","2b2"];
for(o in arr)
{
var bool = isNaN(arr[o]);
document.write(arr[o]+"-"+bool+"<br/>");
}

--其实isNaN更好啊
------解决方案--------------------------------------------------------
变量.typeof = "string";