I have been very busy and have no time to write my own things, but it is not a taste to watch the day without updating my mood. I only have to collect some of the better stuff from the Internet.
/*** Delete spaces at the beginning and end ***/
String. Prototype. Trim = function (){
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}
/*** Count the number of times a specified character appears ***/
String. Prototype. occurs = function (CH ){
// Var Re = eval ("/[^" + CH + "]/g ");
// Return this. Replace (Re, ""). length;
Return this. Split (CH). Length-1;
}
/*** Check whether the data is composed of digits ***/
String. Prototype. isdigit = function (){
VaR S = This. Trim ();
Return (S. Replace (/\ D/g, ""). Length = 0 );
}
/*** Check whether it is composed of digits, letters, and underscores ***/
String. Prototype. isalpha = function (){
Return (this. Replace (/\ W/g, ""). Length = 0 );
}
/*** Check the number of items ***/
String. Prototype. isnumber = function (){
VaR S = This. Trim ();
Return (S. Search (/^ [+-]? [0-9.] * $/)> = 0 );
}
/*** Number of returned bytes ***/
String. Prototype. lenb = function (){
Return this. Replace (/[^ \ x00-\ xFF]/g, "**"). length;
}
/*** Check whether Chinese characters are contained ***/
String. Prototype. isinchinese = function (){
Return (this. length! = This. Replace (/[^ \ x00-\ xFF]/g, "**"). Length );
}
/*** Simple email check ***/
String. Prototype. isemail = function (){
VaR strr;
VaR mail = this;
VaR Re =/(\ W + @ \ W + \. \ W + )(\. {0, 1} \ W *)(\. {0, 1} \ W *)/I;
Re.exe C (Mail );
If (Regexp. $3! = "" & Regexp. $3! = "." & Regexp. $2! = ".")
Strr = Regexp. $1 + Regexp. $2 + Regexp. $3;
Else
If (Regexp. $2! = "" & Regexp. $2! = ".")
Strr = Regexp. $1 + Regexp. $2;
Else
Strr = Regexp. $1;
Return (strr = Mail );
}
/*** Simple date check. The date object is returned successfully ***/
String. Prototype. isdate = function (){
VaR P;
VaR RE1 =/(\ D {4}) [year. /-] (\ D {1, 2}) [month. /-] (\ D {1, 2}) [Day]? $ /;
VaR re2 =/(\ D {1, 2}) [month. /-] (\ D {1, 2}) [Day. /-] (\ D {2}) [year]? $ /;
VaR RE3 =/(\ D {1, 2}) [month. /-] (\ D {1, 2}) [Day. /-] (\ D {4}) [year]? $ /;
If (re1.test (this )){
P = re1.exec (this );
Return new date (P [1], p [2], p [3]);
}
If (re2.test (this )){
P = re2.exec (this );
Return new date (P [3], p [1], p [2]);
}
If (re3.test (this )){
P = re3.exec (this );
Return new date (P [3], p [1], p [2]);
}
Return false;
}
/*** Check whether there are any character characters in the list ***/
String. Prototype. isinlist = function (list ){
VaR Re = eval ("/[" + list + "]/");
Return re. Test (this );
}