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.
Asked
Active
Viewed 2,063 times
-1
-
1public 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 Answers
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