We recommend that you collect JavaScript validation function, you will be able to use the next encounter directly
/*
==================================================================
Is null, only the string is judged
Null or 0 long empty, after trim
Isstringnull (String)
==================================================================
*/
function Isstringnull (str) {
if (str = null)
return true;
var trimstr = Trim (str);
if (trimstr.length = 0)
return true;
return false;
}
/*
==================================================================
LTrim (String): Removing space on the left
==================================================================
*/
function LTrim (str) {
var whitespace = new String ("\t\n\r");
var s = new String (str);
if (Whitespace.indexof (S.charat (0))!=-1) {
var j = 0, i = s.length;
while (J < i && Whitespace.indexof (S.charat (j))!=-1) {
j + +;
}
s = s.substring (j, I);
}
return s;
}
/*
==================================================================
RTrim (String): Remove the space on the right
==================================================================
*/
function RTrim (str) {
var whitespace = new String ("\t\n\r");
var s = new String (str);
if (Whitespace.indexof (S.charat (s.length-1))!=-1) {
var i = s.length-1;
while (i >= 0 && whitespace.indexof (s.charat (i))!=-1) {
i--;
}
s = s.substring (0, i + 1);
}
return s;
}
/*
==================================================================
Trim (String): Remove before and after spaces
==================================================================
*/
function Trim (str) {
Return RTrim (LTrim (str));
}
/*
==================================================================
Isoutoflength (String,int): Determines whether the string is longer than length, Chinese is 2 characters
==================================================================
*/
function Isoutoflength (str, len) {
var strlength = 0;
for (var i = 0; i < str.length; i++) {
if (Str.charcodeat (i) > 256) {
strlength++;
}
strlength++;
if (Strlength > Len) {
return true;
}
}
return false;
}
Current 1/3 page
123 Next read the full text