javascript判斷字符串是否含有特殊字符。具體代碼如下:
funcation checkNum(){
//定義數(shù)組保存特殊字符
var AllNumIsSame = new Array("’","”","!","@","#","$","%","^","&","*",".");
//方法實現(xiàn)
function CheckChar() {
//獲取用戶輸入的數(shù)值
var GetInputValue =$("#InputNumCheck").val();
//初始化
var IsTrueORfalse = false;
//循環(huán)進(jìn)行判斷信息
for (var i = 0; i < AllNumIsSame.length; i++) {
//判斷如果包含鎖定義數(shù)組包含的字符特提示為true
if (GetInputValue.indexOf(AllNumIsSame[i]) != -1) {
IsTrueORfalse = true;
break;
}
}
//如果為true特提示為true否則為false
if (IsTrueORfalse == true) {
alert("true");
}
else {
alert("false");
}
}
}
更多信息請查看IT技術(shù)專欄