中文不能输入超过20,英文输入不能超过40个
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script>
function check(){
var newsTitle=document.getElementById("newsTitle").value;
//表单验证
if(getBLen(newsTitle)>40){
alert("标题不能大于40个字符!中文=20,英文40个");
return;
}
}
function getBLen(str){
if (str == null) return 0;
if (typeof str != "string"){
str += "";
}
return str.replace(/[^x00-xff]/g,"01").length;
}
</script>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script>
function check(){
var newsTitle=document.getElementById("newsTitle").value;
//表单验证
if(getBLen(newsTitle)>40){
alert("标题不能大于40个字符!中文=20,英文40个");
return;
}
}
function getBLen(str){
if (str == null) return 0;
if (typeof str != "string"){
str += "";
}
return str.replace(/[^x00-xff]/g,"01").length;
}
</script>
</head>
<body>
<input type="text" id="newsTitle" onblur="check();" style="width:800px;height:100px;"/>
</body>
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: 32-JAVA把毫秒数转换成日期