These JS codes are some of the code that is frequently used in Form submission. Most of the Code is also written using regular expressions!
// Remove the left space;
Function ltrim (s ){
Return s. replace (/^ \ s */,"");
}
// Remove the right space;
Function rtrim (s ){
Return s. replace (/\ s * $ /,"");
}
// Remove left and right spaces;
Function trim (s ){
Return rtrim (ltrim (s ));
}
// Whether it is null;
Function IsEmpty (_ str ){
Var tmp_str = trim (_ str );
Return tmp_str.length = 0;
}
// Valid Email;
Function IsMail (_ str ){
Var tmp_str = trim (_ str );
Var pattern =/^ [_ a-z0-9-] + (. [_ a-z0-9-] +) * @ [a-z0-9-] + (. [a-z0-9-] +) * $ /;
Return pattern. test (tmp_str );
}
// Valid number;
Function IsNumber (_ str ){
Var tmp_str = trim (_ str );
Var pattern =/^ [0-9]/;
Return pattern. test (tmp_str );
}
// Valid color value;
Function IsColor (color ){
Var temp = color;
If (temp = "") return true;
If (temp. length! = 7) return false;
Return (temp. search (// # [a-fA-F0-9] {6 }/)! =-1 );
}
// Valid link;
Function IsURL (url ){
Var sTemp;
Var B = true;
STemp = url. substring (0, 7 );
STemp = sTemp. toUpperCase ();
If (sTemp! = "HTTP: //") | (url. length <10 )){
B = false;
}
Return B;
}
// Indicates whether the mobile phone number is valid;
Function IsMobile (_ str ){
Var tmp_str = trim (_ str );
Var pattern =/13 \ d {9 }/;
Return pattern. test (tmp_str );
}