JS控制表单不能包含特殊字符的代码

<scriptlanguage="javascript">functioncheckForm(){if(document.form1.Username.value==""... <script language="javascript">
function checkForm(){
if (document.form1.Username.value==""){
alert("请输入用户名称")
return false;
}
else {return true}
}
</script>
<input name="Username" type="text" id="Name4" size="30">

这是限制表单不能为空,否则按提交按扭会弹出对方框(请输入用户名称),是在不跳转页面的情况下弹出对方框的 。我想再多弄几个限制 .
1.限制不能含有特殊字符

2.限制不能含有中文字符

3.限制字符在4-10位 .
展开
 我来答
BingXin_521
推荐于2016-03-22 · 超过52用户采纳过TA的回答
知道答主
回答量:364
采纳率:0%
帮助的人:171万
展开全部
<script language="javascript">
function checkForm(){
var userValue=document.getElementById('nn').value;
var regu= /^([a-zA-Z0-9]|[._]){4,10}$/;
if (userValue =="")
{
alert("请输入用户名称")
return false;
}
else {
if(!regu.exec(userValue))
{
alert("输入错误");
}else
{

alert("输入正确");
return true
}
}
}
</script>
<title>无标题文档</title>
</head>

<body>
<form id="from1">
<input id="nn" name="Username" type="text" size="30"/>
<input type="button" value="提交" onclick="checkForm()"/>
</form>

已经测试过的了,绝对可以用
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yuewutao
2010-11-09 · TA获得超过155个赞
知道小有建树答主
回答量:141
采纳率:0%
帮助的人:99.6万
展开全部
<!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 checkForm(){

//只允许写 英文字母 数字
var text = document.form1.Username.value;
var regu = "[a-zA-Z0-9\.\-]+"//正则表达式
var re = new RegExp(regu);
if(document.form1.Username.value=="" || text.search( re ) == -1 || document.form1.Username.value.length <=4 || document.form1.Username.value.length >=10){
alert("输入有误")
}

}
</script>

</head>

<body>
<form name="form1" id="form1">
<input name="Username" type="text" id="Name4" size="30">
<input type="button" onclick="checkForm()" value="11" />
</form>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
bhnd97
2010-11-10 · TA获得超过175个赞
知道答主
回答量:429
采纳率:0%
帮助的人:248万
展开全部
你给的页面不就有源代码么?

表单
<input name="tbUserName" type="text" id="tbUserName" onFocus="javascript:doCheckUser();" onKeyUp="javascript:doCheckUser();" onBlur="javascript:doCheckLeaveUser();" />

js写的很清楚
再配合表单里的hidden
还有这两个ajax脚本

,_91Wang.WebUI.ashx

耐心理顺一下具体流程~~
请参考
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zpz152
2010-11-12
知道答主
回答量:11
采纳率:0%
帮助的人:1.4万
展开全部
限制可以输入中午,怎么现实
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
anywing2000
2010-11-09 · TA获得超过162个赞
知道小有建树答主
回答量:135
采纳率:0%
帮助的人:111万
展开全部
用正则表达式进行匹配。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式