Java Regular Expression Verification

Source: Internet
Author: User
1 public class RegEx {2 3/** 4 * check whether email input is correct. 5 * the correct format is username @ domain 6 * @ Param value 7 * @ return 8 */ 9 Public Boolean checkemail (string value, int length) {10 return value. matches ("\ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\\. \ W + ([-.] \ W +) * ") & value. length () <= length; 11} 12 13/** 14 * check whether the phone number is correct 15 * correct format 012-87654321, 0123-87654321, 0123-7654321 16 * @ Param value 17 * @ return 18 */19 publi C Boolean checktel (string value) {20 return value. matches ("\ D {4}-\ D {8} | \ D {4}-\ D {7} | \ D (3) -\ D (8 )"); 21} 22 23/** 24 * check whether the mobile phone input is correct 25*26 * @ Param value 27 * @ return 28 */29 public Boolean checkmobile (string value) {30 return value. matches ("^ [1] [3, 5] + \ D {9 }"); 31} 32 33/** 34 * check whether the Chinese name is correctly entered 35*36 * @ Param value 37 * @ return 38 */39 public Boolean checkchinesename (string value, int le Ngth) {40 return value. matches ("^ [\ u4e00-\ u9fa5] + $") & value. length () <= length; 41} 42/** 43 * Check for empty rows or spaces at the beginning and end of HTML 44 * @ Param value 45 * @ return 46 */47 Public Boolean checkblank (string value) {48 return value. matches ("^ \ s * | \ s * $ "); 49} 50/** 51 * check whether the string contains the HTML Tag 52 * @ Param value 53 * @ return 54 */55 56 public Boolean checkhtmltag (string value) {57 Return Value. matches ("<(\ s *?) [^>] *> .*? </\ 1> | <.*? /> "); 58} 59/** 60 * check whether the URL is valid 61 * @ Param value 62 * @ return 63 */64 public Boolean checkurl (string value) {65 return value. matches ("[A-Za-Z] +: // [^ \ s] *"); 66} 67/** 68 * check whether the IP address is valid 69 * @ Param value 70 * @ return 71 */72 public Boolean checkip (string value) {73 return value. matches ("\ D {1, 3} + \\. \ D {1, 3} + \\. \ D {1, 3} + \\. \ D {1, 3} "); 74} 75/** 76 * check whether the ID is valid. It must start with a uppercase/lowercase letter. Other digits can contain uppercase/lowercase characters, numbers, and underscores (_). 77 * @ Param value 78 * @ return 79 */80 public Boolean checkid (string value) {81 return value. matches ("[A-Za-Z] [a-zA-Z0-9 _] {} $"); 82} 83/** 84 * 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 86 * @ return 87 */88 89 Public Boolean checkqq (string value) {90 return value. matches ("[1-9] [0-9] {4, 13 }"); 91} 92/** 93 * check whether the zip code is valid 94 * @ Param value 95 * @ return 96 */97 Public Boolean checkpostcode (S Tring value) {98 return value. Matches ("[1-9] \ D {5 }(?! \ D) "); 99} 100/** 101 * check whether the ID card is valid, 15 or 18-bit 102 * @ Param value 103 * @ return 104 */105 public Boolean checkidcard (string value) {106 return value. matches ("\ D {15} | \ D {18 }"); 107} 108/** 109 * check whether the input exceeds the specified length of 110 * @ Param length 112 * @ Param value 113 * @ return 114 */115 public Boolean checklength (string value, int length) {116 return (value = NULL | "". equals (value. trim ()))? 0: value. length () <= length; 117} 118 119/** 120 * check whether it is a Null String, null: True, not empty: false 121*122 * @ Param value 123 * @ return 124 */125 public Boolean checknull (string value) {126 return value = NULL | "". equals (value. trim (); 127} 128 129}

 

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.