-1

I have an IP address for which I want to define a regular expression to write it in its proper format. Please suggest a way in which I can achieve this.

  • 1
    public static boolean isValidIP(String ipAddr){ Pattern ptn = Pattern.compile("^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$"); Matcher mtch = ptn.matcher(ipAddr); return mtch.find(); } This will work – Akhil Feb 09 '16 at 09:16

1 Answers1

0

You may try this one :

^(([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|2[0-5][0-5]|2[0-4]\d)$
Nikolay Tomitov
  • 947
  • 5
  • 12