I think this is what you want:
^\d+(\.\d+)*$
Explanation: It accepts numbers separated by periods; it begins and ends with a number; a number may have several digits; a single number without dots is also accepted.
Option without multiple digits:
^\d(\.\d)*$
Options where at least one point is required:
^\d+(\.\d+)+$
^\d(\.\d)+$
Don't forget that in Java you need to escape the \ character, so the code will look like this:
Pattern NUMBERS_WITH_DOTS = Pattern.compile("^\\d+(\\.\\d+)*$");
source
share