/** * Stringcheckutil * String Detection Tool * * @version 1.0 * @method isnum (string,scope) * @method Ischin ESE (string,scope) * @method isenglish (string,scope) * @method iscontainsstring (string,substring,case)*/ /** * Isnum (string,scope) * @param string:string resource * @param scope:all,part*/ varStringcheckutil =function() {}; StringCheckUtil.prototype.isNum=function(string, scope) {//Verify parameter legality if((Arguments.length! = 2) | | (typeof(string)! = ' string ') | | (typeof(scope)! = ' String ')) { Throw NewError ("Arguments is not qualified!"); } //Verify Scope Parameters if(scope = ' part ') && (scope! = ' All '))) { Throw NewError ("The argument what named are ' scope ' is not qualified!"); } varRegex_all =/\d*/;//I ignore case varRegex_part =/\d/gi; Switch(scope) { Case' All ': return(String.match (regex_all) = = string)?true:false; Break; Case' Part ': return(Regex_part.test (string)); Break; default: Console.log (' This string is unknown. '); } } /** * iscontainsstring (string,case) * @param string:string resource * @param case:i (case-insentitive): Ignore case , C: (case) does not ignore capitalization **/StringCheckUtil.prototype.isContainsString=function(String, subString, case) {//Verify parameter legality if((Arguments.length! = 3) | | (typeof(string)! = ' string ') | | (typeof(subString)! = ' string ') | | (typeof(case)! = ' String ')) { Throw NewError ("Arguments ' length is not qualified!"); } //Verify Scope Parameters if(Case! = ' I ') && (case! = ' C '))) { Throw NewError ("The argument what named are ' scope ' is not qualified!"); } varRegex_case = (case = = ' I ')? ' I ': '; varRegex_scope = ' g ';//Default: Global varRegex =NewREGEXP (subString, Regex_case +regex_scope); returnregex.test (string); }
Demo:
var string_cs = "89898 67646g 6585dgdf7"; var stringnum = "Jh787kk"; var case_cs = ' I '; var substring_cs = "67646G"; var stringutil_cs = new Stringcheckutil (); Console.log ("Isnum:" + stringutil_cs.isnum (Stringnum, "all"));//must all be integer digits (without decimal points) Console.log ("Isnum:" + Stringutil_cs.isnum (Stringnum, "part");//contains the number Console.log ("iscontainsstring:" + stringutil_ Cs.iscontainsstring (String_cs, Substring_cs, Case_cs)); Ignore case, whether the target string is included
Not to be continued ....
JavaScript string Matching tool [plugin]