<p>长度限制</p>
<!-- onsubmit 属性只在 <form> 表单中使用。 -->
<form name=a "return test()">
<textarea name="b" cols="40" rows="6" placeholder="不能超过50个字符"></textarea>
<input type="submit" name="Submit" value="提交">
</form>
<p>只能是汉字</p>
<input type="text" "isChinese(this.value)" placeholder="请输入中文">
<script type="text/javascript">
function test(){
if(document.a.b.value.length>50){
alert("不能超过50个字符")
document.a.b.focus();
return false;
}
}
function isChinese(obj){
var reg=/^[\u4e00-\u9fa5]+$/;
if(obj !="" && !reg.test(obj)){
alert("必须输入中文")
return false;
}
}
</script>
js表单验证不能超过字数和只能是中文
猜你喜欢
转载自blog.csdn.net/L__MY/article/details/88907115
今日推荐
周排行