Online search for the regular verification mailbox phone and other code

Source: Internet
Author: User

Package com.office.utility;

Import Java.util.regex.Pattern;

/**
* Validator: Use regular expression to check the mailbox, mobile phone number, etc.
*
* @author Liujiduo
*
*/
public class Validator {
/**
* Regular expression: Verify 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: Verify the phone number
*/
public static final String regex_mobile = "^ ((13[0-9]) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ ";

/**
* Regular expression: Verify Mailbox
*/
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: Validating 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: Verify URL
*/
public static final String Regex_url = "http (s)?:/ /([\\w-]+\\.) +[\\w-]+ (/[\\w-./?%&=]*)? ";

/**
* Regular expression: Verify 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 Checksum returns TRUE, otherwise false
*/
public static Boolean Isusername (String username) {
Return Pattern.matches (Regex_username, USERNAME);
}

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

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

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

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

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

/**
* Check URL
*
* @param URL
* @return Checksum returns TRUE, otherwise 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));
}
}

Online search for the regular verification mailbox phone and other code

Related Article

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.