首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

表单字符匹配的有关问题

2012-08-07 
表单字符匹配的问题scriptlanguage javascript functionregcheck(formct){if(formct.id.value![a-g]

表单字符匹配的问题
<script   language= "javascript ">
function   regcheck(formct)   {
if   (formct.id.value   !=[a-g])   {
alert( '编码非法 ');
formct.id.focus();  
return   false;
}
</script>

<body>
<form   action= "in.php "   method= "post "   name= "form1 "   target= "_blank "   onSubmit= 'return   regcheck(this) '>
<input   name= "id "   type= "text "   id= "id "   size= "10 "   maxlength= "10 ">
</form>

问题为表单id只可输入a-g之间的字母(可输入a,也可输入abcdefg),除外都为非法

[解决办法]
if ( !/^[a-g]+$/.test(formct.id.value) ) {
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function regcheck(){
var reg=/^[a-g]+$/i;
var text=document.getElementById("test");
if(!reg.test(text.value)){
alert( '编码非法 ');
text.focus();
return false;
}
return true;
}
</script>

<body>
<form action= "in.php " method= "post " name= "form1 " target= "_blank " onsubmit="return regcheck()">
<input type= "text" id="test" size= "10 " maxlength= "10 ">
</form> 
</body>
</html>
这样?

热点排行
Bad Request.