java中数字和小数的正则表达式

Har*_*pta 3 java regex validation

需要一个允许以下有效值的正则表达式。(只允许小数和数字)

有效的 :

.1  
1.10  
1231313  
0.32131  
31313113.123123123 
Run Code Online (Sandbox Code Playgroud)

无效的 :

dadadd.31232  
12313jn123  
dshiodah  
Run Code Online (Sandbox Code Playgroud)

hwn*_*wnd 5

如果您想严格限制允许的匹配项:

^[0-9]*\.?[0-9]+$
Run Code Online (Sandbox Code Playgroud)

说明

^         # the beginning of the string
 [0-9]*   #  any character of: '0' to '9' (0 or more times)
 \.?      #  '.' (optional)
 [0-9]+   #  any character of: '0' to '9' (1 or more times)
$         # before an optional \n, and the end of the string
Run Code Online (Sandbox Code Playgroud)

现场演示