日期:2014-05-17  浏览次数:20778 次

正则表达式
如何用正则表达式判断一个变量是否是字符串类型的

------解决方案--------------------
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";