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.