//使用说明  只需给要验证的文本框添加一个class属性为:textInputLimit   同时添加一个length属性--用于控制被限制的长度要求(这样自定义一个属性的目的是因为多文本输入不会有maxleng)

 

//根据多行class来限制文本框的输入长度
//将最大输入显示放在属性MaxLength中
function LimitTextInputByClass() {
$(".textInputLimit").keydown(function () {
try {
var length = $(this).attr("length");
if (length != null && length != "") {
//判断MaxLength是否为正整数
if (checkRate(length)) {
LimitMultText(this, length - 1);
}
}
} catch (e) {

}
});
}

//对多行文本框输入长度方法实现
function LimitMultText(e, lengths) {

var str_value = $(e).val();
if (str_value.length > lengths) {
str_value = str_value.substring(0, lengths);
}
$(e).val(str_value);
}

//判断一个书字符串是否为正整数
function checkRate(value) {
var re = /^[1-9]+[0-9]*]*$/;

if (!re.test(value)) {
return false;
}
else {
return true;
}
}

相关文章:

  • 2021-10-11
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-11-03
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
相关资源
相似解决方案