Regular expressions determine IP numbers

Source: Internet
Author: User

1. Regular expressions

             Public Static BOOLCheckip (stringStrIP) {                //string regex = @ "^ (2[0-4]\d | 25[0-5] | [01]?\d? [1-9]) \." +                //@ "(2[0-4]\d | 25[0-5) | [01]?\d?\d) \. "+//@ "(2[0-4]\d | 25[0-5) | [01]?\d?\d) \. "+//@ "(2[0-4]\d | 25[0-5) | [01]?\d?\d) $ ";String regex ="^ (1\\d{2}|2[0-4]\\d|25[0-5]|[ 1-9]\\d| [1-9]) \\."+"(1\\d{2}|2[0-4]\\d|25[0-5]|[ 1-9]\\d|\\d) \ \."+"(1\\d{2}|2[0-4]\\d|25[0-5]|[ 1-9]\\d|\\d) \ \."+"(1\\d{2}|2[0-4]\\d|25[0-5]|[ 1-9]\\d|\\d) $"; if(System.Text.RegularExpressions.Regex.IsMatch (StrIP, Regex)) {return true; }                Else                {                    return false; }            } Public Static BOOLCheckNumber (stringStrText) {String regex="^[1-9]\\d*$";//match numbers and do not start with 0//String regex = "^[0-9]*$"; //Match Numbers                if(System.Text.RegularExpressions.Regex.IsMatch (StrText, Regex)) {return true; }                Else                {                    return false; }            }             Public Static BOOLChecknumout (stringstrnum) {                //String regex = @ "^[\d,]+$";String regex =@"^[\d][\,\d]*$";//match number, comma                if(System.Text.RegularExpressions.Regex.IsMatch (Strnum, Regex)) {return true; }                Else                {                    return false; }            }

            public static void Checkip (TextBox txt, string mes)            {                if (txt. Text.trim ()! = "" &&! Global.Methods.checkIP (txt. Text.trim ()))                {                    txt. Text = "";                    Txt. Focus ();                    if (mes = = "")                        MessageBox.Show ("IP address is not legal", "hint",MessageBoxButtons.OK, messageboxicon.information); else MessageBox.Show (mes + "illegal", "hint",MessageBoxButtons.OK, messageboxicon.information);}}  

  /// <summary>        ///verifies whether a string matches numbers, letters, kanji/// </summary>        /// <param name= "Isnumber" >match numbers or match numbers, letters, kanji</param>        /// <param name= "str" >the input string</param>        /// <param name= "Isreturn" >whether you need to return a string that ignores special characters</param>        /// <returns></returns>        Private BOOLCheckformat (BOOLIsnumber,ref stringStrBOOLIsreturn) {            BOOLresult =false; stringRegex ="^[0-9]*$";//Match Numbers            if(! Isnumber) regex =@"^[\w]+$";//match numbers, letters, kanji            varReg =NewSystem.Text.RegularExpressions.Regex (Regex);//             //var str = this. Text.replace (", " "");            varSB =NewStringBuilder (); if(Reg. IsMatch (str)) {result=true; }            Else            {                if(Isreturn) { for(inti =0; I < Str. Length; i++)                    {                        if(Reg. IsMatch (Str[i]. ToString ())) {sb. Append (Str[i].                        ToString ()); }} str=sb.                ToString (); }            }            returnresult; }    

Regular expressions determine IP numbers

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.