相思资源网 Design By www.200059.com
复制代码 代码如下:
/检查非法字符并检验字符长度
function checkSpeChar(obj, byteLength, title) {
var value = document.getElementById(obj).value;
value = value.replace(/(^\s*)/g, "").replace(/(\s*$)/g, "");
var ret = (/[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']/.test(value));
var arr = ["@", "#", "$", "%", "^", "&", "*", "<", ">", "/", "\\", "\'", "'", ".", ":", "?", "[", "]", ";", "-", "、", "(", ")", "_", "\"", "~", "insert", "delete", "update", "select"];
value = value.toLowerCase();
for (var i = 0; i < arr.length; i++) {
if (value.indexOf(arr[i].toLowerCase()) >= 0) {
ret = true;
}
}
if (ret == true) {
top.LSAlert("内容中含非法字符,请重新输入!");
document.getElementById(obj).value = '';
return;
}
limitLength(value, byteLength, title, obj);
}
//验证输入字符长度
function limitLength(value, byteLength, title, attribute) {
value = value.replace(/\r/g, " ").replace(/\n/g, " "); //回车换行分别替换两个空格
var newvalue = value.replace(/[^\x00-\xff]/g, "***");
var length = newvalue.length;
//当填写的字节数小于设置的字节数
if (length * 1 <= byteLength * 1) {
return;
}
var limitDate = newvalue.substr(0, byteLength);
var count = 0;
var limitvalue = "";
for (var i = 0; i < limitDate.length; i++) {
var flat = limitDate.substr(i, 1);
if (flat == "*") {
count++;
}
}
var size = 0;
var istar = newvalue.substr(byteLength * 1 - 1, 1); //校验点是否为“×”
//if 基点是×;
if (count % 3 == 0) {
size = count / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
else if (count % 3 == 1) {
size = (count - 1) / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
else if (count % 3 == 2) {
size = (count - 2) / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
//top.LSAlert(title + "最大输入" + byteLength + "个字节!");
document.getElementById(attribute).value = limitvalue;
return;
}
/检查非法字符并检验字符长度
function checkSpeChar(obj, byteLength, title) {
var value = document.getElementById(obj).value;
value = value.replace(/(^\s*)/g, "").replace(/(\s*$)/g, "");
var ret = (/[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']/.test(value));
var arr = ["@", "#", "$", "%", "^", "&", "*", "<", ">", "/", "\\", "\'", "'", ".", ":", "?", "[", "]", ";", "-", "、", "(", ")", "_", "\"", "~", "insert", "delete", "update", "select"];
value = value.toLowerCase();
for (var i = 0; i < arr.length; i++) {
if (value.indexOf(arr[i].toLowerCase()) >= 0) {
ret = true;
}
}
if (ret == true) {
top.LSAlert("内容中含非法字符,请重新输入!");
document.getElementById(obj).value = '';
return;
}
limitLength(value, byteLength, title, obj);
}
//验证输入字符长度
function limitLength(value, byteLength, title, attribute) {
value = value.replace(/\r/g, " ").replace(/\n/g, " "); //回车换行分别替换两个空格
var newvalue = value.replace(/[^\x00-\xff]/g, "***");
var length = newvalue.length;
//当填写的字节数小于设置的字节数
if (length * 1 <= byteLength * 1) {
return;
}
var limitDate = newvalue.substr(0, byteLength);
var count = 0;
var limitvalue = "";
for (var i = 0; i < limitDate.length; i++) {
var flat = limitDate.substr(i, 1);
if (flat == "*") {
count++;
}
}
var size = 0;
var istar = newvalue.substr(byteLength * 1 - 1, 1); //校验点是否为“×”
//if 基点是×;
if (count % 3 == 0) {
size = count / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
else if (count % 3 == 1) {
size = (count - 1) / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
else if (count % 3 == 2) {
size = (count - 2) / 3 + (byteLength * 1 - count);
limitvalue = value.substr(0, size);
}
//top.LSAlert(title + "最大输入" + byteLength + "个字节!");
document.getElementById(attribute).value = limitvalue;
return;
}
标签:
特殊字符,用户输入长度
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无删除特殊字符和限定用户输入长度的示例代码的评论...