how to check Binary point number validation in java?

example:-

valid binary number = 1010111 // true

valid Binary point number = 101011.11 // true

Invalid Binary number = 152.35 // false

how to check?

Answer

You can use the regex, [01]*.?[01]+

import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        //Test
        Stream.of(
                    "1010111",
                    "101011.11",
                    "101.011.11",
                    "152.35"
                ).forEach(s -> System.out.println(s + " => " + isBinary(s)));
    }
    
    static boolean isBinary(String s) {
        return s.matches("[01]*\.?[01]+");
    }
}

Output:

1010111 => true
101011.11 => true
101.011.11 => false
152.35 => false

Explanation of the regex at regex101:

enter image description here