表单递交合法性检测-不允许指定字符 

 1<script language="JavaScript">   
 2<!--//   
 3function validate(){   
 4var invalid = " "; //非法字符是空格你可以改为其它字符或数字   
 5if (document.submitform.filename.value.indexOf(invalid) > -1) {   
 6alert("文件名不能含有空格!");   
 7return false;   
 8}   
 9else {   
10return true;   
11}   
12}   
13// -->   
14</script>
1<form name="submitform" onsubmit="return validate()">
2<input name="filename" type="file"/>
3<p>
4<input type="submit" value="Submit"/>
5</p></form>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus