Regular expressions commonly used in Java, such as IP address, phone number, mailbox, etc.

Source: Internet
Author: User

Java we will often use a number of judgments such as IP, e-mail, telephone number is not in line with, then we how to judge it, the answer is to use regular expression to judge, because I do not have too deep research on the regular expression, all interested friends can own Baidu. I will give the basic judgment, the nonsense is not much to say, the following is the code.

How to determine IP address

public static Boolean Orip (String IP) {if (IP = = NULL | | "". Equals (IP)) return false; String regex = "^ (1\\d{2}|2[0-4]\\d|25[0-5]|[ 1-9]\\d| [1-9]) \\." + "(1\\d{2}|2[0-4]\\d|25[0-5]| [1-9]\\d|\\d] \ \. " + "(1\\d{2}|2[0-4]\\d|25[0-5]| [1-9]\\d|\\d] \ \. " + "(1\\d{2}|2[0-4]\\d|25[0-5]| [1-9]\\d|\\d) $ "; return ip.matches (regex);}

Determine if the email address is correct



return email.matches (regex);
}

Determine if it is a mobile phone number

public static Boolean Orphonenumber (String phonenumber) {if (PhoneNumber = = NULL | | "". Equals (PhoneNumber)) return false; String regex = "^1[3|4|5|8][0-9]\\d{8}$"; return phonenumber.matches (regex);}

  

Regular expressions commonly used in Java, such as IP address, phone number, mailbox, etc.

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.