JavaScript validation functions often used to collect 1th/3 page _javascript Tips

Source: Internet
Author: User
Tags rtrim
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.