JavaScript判断字符串是否合法

<!DOCTYPE html>
<html>
<head>
<title>判断字符串是否合法</title>
<script>
function isRight(subChar){
     var findChar="adcdefgjshfsjhfsdkfhifjkfd243674653475_-";
	 for(var i=0;i<subChar.length;i++){
	         if(findChar.indexOf(subChar.charAt(i))==-1){
			       alert("你的字符串不合法");
				   return;
			 }
	 }
	 alert("你的字符串合法");
}
</script>
</head>
<body>
<form action="" method="post" name="myform" id="myform">
  <input type="text" name="txtString">
  <input type="button" value="检  查" οnclick="isRight(document.myform.txtString.value)">
</form>
</body>
</html>

posted @ 2015-07-20 20:20  wojiaohuangyu  阅读(13)  评论(0)    收藏  举报