Tag Archives: formatting

[Java] – Regular expression to match IPv4 address

I saw such question on SO. There was no solution with RegEx so… I was bored I think.

public static boolean isValid(String ip) {
    boolean isvalid;
 
    isvalid = ip.matches(
            "(([0-9]|[0-9]{0,2}|1[0-9]*{0,2}|2[0-5][0-5]|0{0,3}).){3}" +
             "([0-9]|[0-9]{0,2}|1[0-9]*{0,2}|2[0-5][0-5]|0{0,3})"
    );
 
    return isvalid;
}

Continue reading