日期:2014-05-18 浏览次数:20602 次
<form name=loginform>
<input type="text" name="txtName" size="20">
<input name="Submit" type="submit" class="button1" onclick="check()">
</form>
<script language=JavaScript>
function check()
{
var reg = /^[a-zA-Z0-9]{5,20}$/;
if(!reg.test(document.loginform.txtName.value))
{
alert("不合法!");
}
}
</script>
------解决方案--------------------
要是在cs代码中写程序那你就把你要验证的那个字符串加上一个.trim()不就能把空格去掉吗,不知道我理解的对不对。