当前页面: 开发资料首页 → J2SE 专题 → 验证money类型的正则该怎么写?
验证money类型的正则该怎么写?
摘要: 验证money类型的正则该怎么写?
RT
比如 100 要能过 100.5 也要能过.
现在的处理是让他match -#34;//d+-#34; 也就是int型 或者 match -#34;//d+//.?//d+-#34; 也就是带小数点的
能不能写成一个正则表达式.
半天没人来看看呢 ~ 自己顶
没看懂你的题目什么意思 帮你顶下 呵呵
(//.[//d]+)|([//d]+//.[//d]+)|([//d]+)
测试
.5
10.5
10
通过
([/d]+)(/.[/d]{0,2})?
0.01
0.1
100
100.05
100.00
100.1
都通过
哈哈鱼的我在匹配测试上通不过.
执子之手的基本满足了.
在java里面 是不是要写成 ([//d]+)(//.[//d]{0,2})?
要不会报错
package net.xiaobin.test;
import java.util.regex.Pattern;
public class RegexTest {
private static void run(String args) {
Pattern fPattern = Pattern.compile(-#34;^//d{1,}//.//d{1,2}$-#34;);
Pattern iPattern = Pattern.compile(-#34;^//d{1,}$-#34;);
if (fPattern.matcher(args).find()) {
System.out.println(args + -#34;:浮点型-#34;);
} else if (iPattern.matcher(args).find()) {
System.out.println(args + -#34;:整型-#34;);
} else {
System.out.println(args + -#34;:类型未知-#34;);
}
}
public static void main(String[] args) {
run(-#34;0.01-#34;);
run(-#34;0.001-#34;);
run(-#34;100.03-#34;);
run(-#34;50-#34;);
run(-#34;50.1-#34;);
}
}