js校验字符长度(一个中文占两个字符)
2017-01-03 10:03
288 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<script src = "jquery-1.4.js"></script>
<div class="box">
<span>请选择</span>
<div class="content">
<textarea id="nojoinreasoncode" name="nojoinreasoncode" rows="4" style="width:400px;" ></textarea>
</div>
<input type="button" id="checkorgentity" value="提交">
</div>
<script>
$(function(){
$("#checkorgentity").click(function(){
//得到属性值
var nojoinreasoncode = document.getElementById("nojoinreasoncode").value;
alert("nojoinreasoncode=="+nojoinreasoncode);
var othernolen = checkothernolen(nojoinreasoncode);
alert("othernolen=="+othernolen);
if(othernolen>30){
alert("证件号码有误!!!!!!");
}
});
})
//校验填写的证件(除身份证外)号码,长度不能超过30个字符
function checkothernolen(certno) {
var certnolen;
var i;
certnolen = 0;
if (certno == "" || certno == undefined) {
flag = false;
} else {
for (i = 0; i < certno.length; i++) {
if (certno.charCodeAt(i) > 255) certnolen += 2;
else certnolen++;
}
}
return certnolen;
}
</script>
</body>
</html>
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<script src = "jquery-1.4.js"></script>
<div class="box">
<span>请选择</span>
<div class="content">
<textarea id="nojoinreasoncode" name="nojoinreasoncode" rows="4" style="width:400px;" ></textarea>
</div>
<input type="button" id="checkorgentity" value="提交">
</div>
<script>
$(function(){
$("#checkorgentity").click(function(){
//得到属性值
var nojoinreasoncode = document.getElementById("nojoinreasoncode").value;
alert("nojoinreasoncode=="+nojoinreasoncode);
var othernolen = checkothernolen(nojoinreasoncode);
alert("othernolen=="+othernolen);
if(othernolen>30){
alert("证件号码有误!!!!!!");
}
});
})
//校验填写的证件(除身份证外)号码,长度不能超过30个字符
function checkothernolen(certno) {
var certnolen;
var i;
certnolen = 0;
if (certno == "" || certno == undefined) {
flag = false;
} else {
for (i = 0; i < certno.length; i++) {
if (certno.charCodeAt(i) > 255) certnolen += 2;
else certnolen++;
}
}
return certnolen;
}
</script>
</body>
</html>
相关文章推荐
- JS获取字符串长度,一个中文算两个字符。
- 写了一个字符串截取一定长度的代码,中文两个字符,英文一个字符,如果截断了自动用一个.或两个.来对齐,用于标题的显示
- JS获取字符串长度(中文占两个,数字与英文占一个)
- js判断输入字符串长度(汉字算两个字符,字母数字算一个)
- python 计算字符串长度,一个中文算两个字符
- js判断字符串长度,中文占两个字符
- js判断输入字符串长度(汉字算两个字符,字母数字算一个)
- js字符限制(字符截取) 一个中文汉字算两个字符
- javascript计算中文字符长度(一个中文字符相当于两个英文字符)
- js字符串长度计算(一个汉字==两个字符)和字符串截取
- JS 判断输入字符串的长度(中文占用两个字节,英文占用一个字节)
- 计算文本长度,区分中英文字符,中文算两个长度,英文算一个长度
- JS判断输入字符串长度(汉字算两个字符,字母数字算一个)
- js计算一个字符中包括中英文的长度,中文占2个字符,汉子和英文占1个字符
- 截取文本,区分中英文字符,中文算两个长度,英文算一个长度
- JS 判断输入字符串的长度(中文占用两个字节,英文占用一个字节)
- js脚本系列(1) JS判断输入字符串长度(汉字算两个字符,字母数字算一个)
- js判断输入字符串长度(汉字算两个字符,字母数字算一个)
- JS判断输入字符串长度实例代码(汉字算两个字符,字母数字算一个)
- javascript 返回字符长度,中文为两个字节,英文为一个字节