JavaScript string Matching tool [plugin]

Source: Internet
Author: User

/** * 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]

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.