数字长度 验证
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" rows="6" placeholder="不能超过50个字符!"></textarea>
<br />
<input type="submit" name="Submit" value="check">
</form>
<script language="javascript">
function test()
{
if(document.a.b.value.length>50)
{
alert("不能超过50个字符!");
document.a.b.focus();
return false;
}
}
</script>
不能为空
function checkpass(){
var pass=$("#p").get(0).value;
if (pass.trim() == '') {
$("#pass").get(0).innerHTML="<font color='red'>密码不能为空</font>";
}else{
$("#pass").get(0).innerHTML="";
}
}
密码<input name="password" id="p" onblur="checkpass()"><span id="pass"></span><br>
function checkemail(){
var email=$("#e").get(0).value;
if (email.indexOf("@") == -1) {
$("#email").get(0).innerHTML="<font color='red'>邮箱必须包含‘@’符号</font>";
}else{
$("#email").get(0).innerHTML="";
}
}
邮箱<input name="email" id="e" onblur="checkemail()"><span id="email"></span><br>
邮箱验证