SoFunction
Updated on 2025-03-01

JS TextArea string length limit code collection


<html>
<body>
<textarea ></textarea>
<input type="text" />
<script type="text/javascript">
textAreaLimit("t",{lastMsgLabel:"b2"})
function textAreaLimit(area,op){
var defaultOp = {
maxLength:10 //Maximum length
, IsNumber:false // can only be a number
, lastMsgLabel:null //Instant display of Input with the number of inputs
, msg:"You can also enter {0} text"
, errorMsg:"The number of text exceeds the maximum limit"
};
var label;
if(typeof area == "string"){
area = (area);
}
if(!area){
return;
}
for(var i in op){
defaultOp[i] = op[i];
}
if(){
if(typeof == "string"){
label = ();
}
}
if(){
="Disabled";//IE
= function(){
return != 229;
}
}
= function(){
if(){
= (/\D/g,"");//Other than IE
}
if( > ){
//-------------------------------------------------------------------------------
//Plan ①
= "disabled";
= (0,);
("disabled");
();
//Plan ②
//or
//alert();
// = (0,);
//-------------------------------------------------------------------------------
}
if(label){
= (/\{0\}/, -);
}
}
}
</script>
</body>
</html>