Java Regular Expression Verification

Source: Internet
Author: User

Public class Regex {/*** check whether email input is correct * correct format: username @ domain * @ param value * @ return */public boolean checkEmail (String value, int length) {return value. matches ("\ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\\. \ w + ([-.] \ w +) * ") & value. length () <= length ;} /*** check whether the phone number is entered correctly * correct format 012-87654321, 0123-87654321, 0123-7654321 * @ param value * @ return */public boolean checkTel (String value) {return value. matches ("\ d {4 }-\ \ D {8} | \ d {4}-\ d {7} | \ d (3)-\ d (8 )");} /*** check whether the mobile phone input is correct ** @ param value * @ return */public boolean checkMobile (String value) {return value. matches ("^ [1] [3, 5] + \ d {9 }");} /*** check whether the Chinese name is entered correctly ** @ param value * @ return */public boolean checkChineseName (String value, int length) {return value. matches ("^ [\ u4e00-\ u9fa5] + $") & value. length () <= length;}/*** check the first and last blank lines or spaces in HTML * @ param value * @ return */public boolean checkBl Ank (String value) {return value. matches ("^ \ s * | \ s * $ ");} /*** check whether the String contains the HTML Tag * @ param value * @ return */public boolean checkHtmlTag (String value) {return value. matches ("<(\ S *?) [^>] *> .*? </\ 1> | <.*? /> ");}/*** Check whether the URL is valid * @ param value * @ return */public boolean checkURL (String value) {return value. matches ("[a-zA-z] +: // [^ \ s] *");} /*** check whether the IP address is valid * @ param value * @ return */public boolean checkIP (String value) {return value. matches ("\ d {1, 3} + \\. \ d {1, 3} + \\. \ d {1, 3} + \\. \ d {1, 3} ");}/*** check whether the ID is valid and must start with a uppercase/lowercase letter, other characters can contain uppercase and lowercase characters, numbers, and underscores * @ param value * @ return */public boolean checkID (String value) {return value. matche S ("[a-zA-Z] [a-zA-Z0-9 _] {} $");}/*** check if QQ is valid and must be a number, and the first digit cannot be 0, and the maximum length is 15 * @ param value * @ return */public boolean checkQQ (String value) {return value. matches ("[1-9] [0-9] {4, 13 }");} /*** check whether the zip code is valid * @ param value * @ return */public boolean checkPostCode (String value) {return value. matches ("[1-9] \ d {5 }(?! \ D) ");}/*** check whether the ID card is valid, 15 or 18 digits * @ param value * @ return */public boolean checkIDCard (String value) {return value. matches ("\ d {15} | \ d {18 }");} /*** check whether the input exceeds the specified length * @ param value * @ return */public boolean checkLength (String value, int length) {return (value = null | "". equals (value. trim ()))? 0: value. length () <= length;}/*** check whether it is a Null String, null: true, not null: false ** @ param value * @ return */public boolean checkNull (String value) {return value = null | "". equals (value. trim ());}}


This article is from the "chenlinben" blog, please be sure to keep this source http://linben.blog.51cto.com/6205951/1300569

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.