Java validation form, regular expression

Source: Internet
Author: User
Tags form tools

package org.mo.open.common.util;/** *  Check form tools  *  *  @author  moziqi  * */public final class regexvalidateutil {private regexvalidateutil ()  {}private static boolean flag = false;private static String  regex =  "";/** *  verify QQ number  *  *  @param  QQ *  @return  * /PUBLIC STATIC BOOLEAN CHECKQQ (STRING QQ)  {String regex =  "^\\s*[.0-9" {5,10}\\s*$ "; Return check (Qq, regex);} /** *  Verify mobile number  *  *  Mobile number segment: 139, 138, 137, 136, 135, 134, 150, 151, 152, 157, 158, 159, 182, 183, 187, 188, 147 *  unicom number segment: 130, 131, 132, 136, 185, 186, 145  Telecom number segment: 133, 153, 180, 189 *  *  @param  cellphone *  @return  */public static boolean checkcellphone (String  cellphone)  {String regex =  "^ (13[0-9) | ( 14[5|7]) | (15 ([0-3]|[ 5-9])) | (18[0,5-9])) \\d{8}$ "; Return check (Cellphone, regex);} /** *  Verifying landline numbers  *  *  @param  telephone *  @return  */public  Static boolean checktelephone (string telephone)  {String regex =  "^ (0\\d{2}- \\d{8} (-\\d{1,4})?) | (0\\d{3}-\\d{7,8} (-\\d{1,4})?) $ "; Return check (Telephone, regex);} /** *  Verify Fax number  *  *  @param  fax *  @return  */public static  boolean checkfax (string fax)  {String regex =  "^ (0\\d{2}-\\d{8} (-\\d{1,4})?) | (0\\d{3}-\\d{7,8} (-\\d{1,4})?) $ "; Return check (Fax, regex);} /** *  Verification Email  *  *  @param  email *  @return  */public static  boolean checkemail (string email)  {String regex =  "^\\s*\\w+ (?: \ \. {0,1} [\\w-]+) *@[a-za-z0-9]+ (?: [-.] [a-za-z0-9]+] *\\. [a-za-z]+\\s*$]; Return check (Email, regex);} /** *&nbSP; Verify non-empty  *  *  @param  notEmputy *  @return  */public static  Boolean checknotemputy (string notemputy)  {regex =  "^\\s*$"; Return check ( Notemputy, regex)  ? false : true;} Private static boolean check (String str, string regex)  {try {flag  = str.matches (regex);}  catch  (Exception e)  {flag = false;} Return flag;}}


Java validation form, regular expression

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.