Regular expressions in common use--regular expressions

Source: Internet
Author: User
String regex = "^[1-9][0-9]{4,} $";


Package com.office.utility;

Import Java.util.regex.Pattern;

/**
* Calibrator: The use of regular expressions to check the mailbox, mobile phone number, etc.
*
* @author Liujiduo
*
*/
public class Validator {
/**
* Regular expression: Validating user name
*/
public static final String regex_username = "^[a-za-z]\\w{5,17}$";

/**
* Regular expression: Verify password
*/
public static final String Regex_password = "^[a-za-z0-9]{6,16}$";

/**
* Regular expression: Verification of mobile phone number
*/
public static final String regex_mobile = "^ (13[0-9]) | ( 15[^4,\\D]) | (18[0,5-9]) \\d{8}$ ";

/**
* Regular Expressions: Verifying mailboxes
*/
public static final String regex_email = "^" ([a-z0-9a-z]+[-|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+)/\.) +[a-za-z]{2,}$ ";

/**
* Regular Expressions: Verifying Chinese characters
*/
public static final String Regex_chinese = "^[\u4e00-\u9fa5],{0,}$";

/**
* Regular expression: Verify ID
*/
public static final String Regex_id_card = "(^\\d{18}$) | (^\\d{15}$) ";

/**
* Regular expression: Validating URL
*/
public static final String Regex_url = "http (s)?:/ /([\\w-]+\\.) +[\\w-]+ (/[\\w-/?%&=]*)? ";

/**
* Regular expression: Verifying IP Address
*/
public static final String regex_ip_addr = "(25[0-5]|2[0-4]\\d|[ 0-1]\\d{2}| [1-9]?\\d) ";

/**
* Verify user name
*
* @param username
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean Isusername (String username) {
Return Pattern.matches (Regex_username, USERNAME);
}

/**
* Verify Password
*
* @param password
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean Ispassword (String password) {
Return Pattern.matches (Regex_password, PASSWORD);
}

/**
* Check cell phone number
*
* @param Mobile
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean IsMobile (String mobile) {
Return Pattern.matches (Regex_mobile, MOBILE);
}

/**
* Check Mailbox
*
* @param Email
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean isemail (String email) {
Return Pattern.matches (Regex_email, EMAIL);
}

/**
* Check Chinese characters
*
* @param Chinese
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean Ischinese (String Chinese) {
Return pattern.matches (Regex_chinese, Chinese);
}

/**
* Check ID Card
*
* @param idcard
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean Isidcard (String idcard) {
Return Pattern.matches (Regex_id_card, Idcard);
}

/**
* Verify URL
*
* @param URL
* @return Validation returns TRUE, otherwise returns false
*/
public static Boolean isurl (String URL) {
Return Pattern.matches (Regex_url, URL);
}

/**
* Verify IP Address
*
* @param ipaddr
* @return
*/
public static Boolean isipaddr (String ipaddr) {
Return Pattern.matches (REGEX_IP_ADDR, ipaddr);
}

public static void Main (string[] args) {
String username = "FDSDFSDJ";
System.out.println (Validator.isusername (username));
System.out.println (Validator.ischinese (username));
}
}

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.