My idea is something like this but I dont know the correct code
if (mystring.matches(\"[0-9.]+\")){
//do something here
}else{
//do something here
}
<
I think using regexes complicates the answer. A simpler approach is to use indexOf()
and substring()
:
int index = mystring.indexOf(".");
if(index != -1) {
// Contains a decimal point
if (mystring.substring(index + 1).indexOf(".") == -1) {
// Contains only one decimal points
} else {
// Contains more than one decimal point
}
}
else {
// Contains no decimal points
}