java - Check if a string has a particular format? -
i need boolean
check if given string follows below format:
x.x.x or 1.2.3 , x single digit
if string format == x.x.x true. if string format != x.x.x false.
how can achieve this?
you can try using regex:
string x = "9.8.7"; boolean matches = x.matches("\\d\\.\\d\\.\\d"); // true
notice dot .
being escaped \\.
, because has special meaning in regex.
here input/output samples:
"99.8.7" -> false "9.9.7." -> false "9.97" -> false
Comments
Post a Comment