Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.utils;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class IPUtils {
- public static boolean isValidIPAddress(String ip)
- {
- String zeroTo255
- = "(\\d{1,2}|(0|1)\\"
- + "d{2}|2[0-4]\\d|25[0-5])";
- String regex
- = zeroTo255 + "\\."
- + zeroTo255 + "\\."
- + zeroTo255 + "\\."
- + zeroTo255;
- Pattern p = Pattern.compile(regex);
- // If the IP address is empty
- // return false
- if (ip == null) {
- return false;
- }
- // Pattern class contains matcher() method
- // to find matching between given IP address
- // and regular expression.
- Matcher m = p.matcher(ip);
- // Return if the IP address
- // matched the ReGex
- return m.matches();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment