T
the87boy
Why do this regular expression not work:
if (str.matches("^\\d*$") || str.matches("^\\d*" + dot + "$") ||
str.matches("^\\d*" + dot + "\\d*$")) {
return true;
} else {
return false;
}
dot is a string, who looks like this:
String dot = ",";
The 1st regular expression test if it is just a number
The 2nd regular expression test if it is a number and ends with a dot
The 3rd regular exression test if it is a dot sorrunded by numbers
It's only number (can be with a dot)
Can somebody tell me, what's wrong and maybe shorten it?
if (str.matches("^\\d*$") || str.matches("^\\d*" + dot + "$") ||
str.matches("^\\d*" + dot + "\\d*$")) {
return true;
} else {
return false;
}
dot is a string, who looks like this:
String dot = ",";
The 1st regular expression test if it is just a number
The 2nd regular expression test if it is a number and ends with a dot
The 3rd regular exression test if it is a dot sorrunded by numbers
It's only number (can be with a dot)
Can somebody tell me, what's wrong and maybe shorten it?