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

标签 java regex validation

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

有效:

.1  
1.10  
1231313  
0.32131  
31313113.123123123 

无效:

dadadd.31232  
12313jn123  
dshiodah  

最佳答案

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

^[0-9]*\.?[0-9]+$

解释:

^         # 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

Live Demo

关于java - java中数字和小数的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24974816/

相关文章:

c# - 带有第一个大写字符+数字的正则表达式

java - 如何按空格分割字符串(有异常(exception))

c# - 如何在 Spring.NET 中使用 EmailValidator?

java - 格式化字符串内容 xtext 2.14

java - 如何比较android上的两个复选框值?

regex - 匹配文件中最后一个换行符的正则表达式

Angular 验证不适用于模式属性

validation - 有没有办法在 Mongoose 中定义没有 .save() 方法的模型?

java - 有没有办法缩小 BufferedImage

java - 从 Qt C++ 调用 Java 函数