Java Regular Expression validation non-original

Source: Internet
Author: User

1 /**2  * 3  */4  PackageCom.ssh.util;5 6 ImportJava.util.regex.Matcher;7 ImportJava.util.regex.Pattern;8 9 /**Ten  * @authorLeorain One  * A  */ -  Public classValidateutil { -     /** the * Mobile phone number verification -      *  -      * @paramStr -      * @returnverify by returning True +      */ -      Public Static Booleanismobile (String str) { +Pattern p =NULL; AMatcher m =NULL; at         Booleanb =false;  -p = pattern.compile ("^[1][3,4,5,8][0-9]{9}$");//Verify your phone number -m =P.matcher (str); -b =m.matches (); -         returnb; -     } in     /** - * Phone number verification to      *  +      * @paramStr -      * @returnverify by returning True the      */ *      Public Static BooleanIsphone (String str) { $Pattern P1 =NULL, p2 =NULL;Panax NotoginsengMatcher m =NULL; -         Booleanb =false;  theP1 = Pattern.compile ("^[0][1-9]{2,3}-[0-9]{5,10}$");//Verify that the code with the +P2 = pattern.compile ("^[1-9]{1}[0-9]{5,8}$");//Verify that no area code is A         if(Str.length () >9) the{m =P1.matcher (str); +b =m.matches ();  -}Else{ $m =P2.matcher (str); $b =m.matches (); -         }   -         returnb; the     } -     /**Wuyi * Date format Verification the      * @paramStr -      * @returnverify by returning True Wu      * */ -      Public Static Booleanformatedate (String str) { AboutString el= "^ ((\\d{2} (([02468][048]) | ( [13579] [26])) [\\-\\/\\s]? (((0? [13578]) | (1[02])) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9])))) | (\\d{2} ([02468][1235679]) | ( [13579] [01345789])) [\\-\\/\\s]? (((0? [13578]) | (1[02])) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (3[01])) | ((0? [469]) | (11)) [\\-\\/\\s]? ((0? [1-9]) | ([1-2][0-9]) | (30))) | (0?2[\\-\\/\\s]? ((0? [1-9]) | (1[0-9]) | (2[0-8])))) ";  $Pattern p =Pattern.compile (EL);  -Matcher m =P.matcher (str);  -         BooleanFlag =m.matches ();  -         returnFlag;  A         } +      the     /** -      * @paramT $      * @return the      */ the      Public Static<textendsJava.util.date>java.util.Date toutil (T t) { theJava.util.Date Date =T; the         returndate; -     } in  the  the     enumType { About DATE, time, TIMESTAMP the     } the@SuppressWarnings ("Unchecked") the      Public Static<textendsJava.util.date>T tosql (java.util.Date utildate, + Type type) { -T t =NULL; the         LongMillionseconds =utildate.gettime ();Bayi  the         Switch(type) { the          CaseDATE: -t = (t)Newjava.sql.Date (millionseconds); -              Break; the          CaseTime : thet = (t)NewJava.sql.Time (millionseconds); the              Break; the          CaseTIMESTAMP: -t = (t)NewJava.sql.Timestamp (millionseconds); the              Break; the         default: the              Break;94         } the         returnT; the     } the     /**98     * About     * @parama - * The long string that is matched101     * @paramb102 * Matching short string103     * @returnNumber of matches104     */ the     Public intHit (string A, string b) {106        if(A.length () <b.length ()) {107            return0;108        }109        Char[] a_t =A.tochararray (); the        Char[] b_t =B.tochararray ();111        intCount = 0, temp = 0, j = 0; the 113         for(inti = 0; i < a_t.length; i++) { the            //ensure that a continuous string B matches a segment in a the            if(A_t[i] = = B_t[j] && J <b_t.length) { thetemp++;117J + +;118                //The continuous string b matches a segment in a119                if(temp = =b_t.length) { -count++;121temp = 0;122j = 0;123                }124            } the            //as long as there is a character mismatch, the temp count is never126            Else {127temp = 0; -j = 0;129            } the        }131  the        returncount;133    }134}

Java Regular Expression validation non-original

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.