I want a java regex expression that accepts only the numbers and dots.
for example,
1.1.1 ----valid
1.1 ----valid
1.1.1.1---valid
1. ----not valid
The dots should not be at the starting position or at the ending position.
I guess this is what you want:
Explanation: It accepts numbers separated by dots; it starts and ends with number; a number can have multiple digits; one number without dots is also accepted.
Variant without multiple digits:
Variants where at least one dot is required:
Don’t forget that in Java you have to escape the \ symbols, so the code will look like this: