Copy codeThe Code is as follows:
/Check invalid characters and length
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 ("the content contains invalid characters. Please try again! ");
Document. getElementById (obj). value = '';
Return;
}
LimitLength (value, byteLength, title, obj );
}
// Verify the length of input characters
Function limitLength (value, byteLength, title, attribute ){
Value = value. replace (/\ r/g, ""). replace (/\ n/g, ""); // press enter to replace two spaces
Var newvalue = value. replace (/[^ \ x00-\ xff]/g ,"***");
Var length = newvalue. length;
// When the number of bytes entered is smaller than the set number of bytes
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); // check whether the checkpoint is "×"
// If the base point is;
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 + "maximum input" + byteLength + "bytes! ");
Document. getElementById (attribute). value = limitvalue;
Return;
}