Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static boolean validIP(String ip) { if (ip == null || ip.length() < 7 || ip.length() > 15) return false; if (ip.contains("-")) return false; try { int x = 0; int y = ip.indexOf('.'); if (y != -1 && Integer.parseInt(ip.substring(x, y)) > 255) return false; x = ip.indexOf('.', ++y); if (x != -1 && Integer.parseInt(ip.substring(y, x)) > 255) return false; y = ip.indexOf('.', ++x); return !(y != -1 && Integer.parseInt(ip.substring(x, y)) > 255 && Integer.parseInt(ip.substring(++y, ip.length() - 1)) > 255 && ip.charAt(ip.length() - 1) != '.'); } catch (NumberFormatException e) { return false; } } }