校验dubbo类型的数据是否为正整数

来源:互联网 发布:神舟游戏本 知乎 编辑:程序博客网 时间:2024/05/17 04:59

直接看代码

/** * 判断是否为正整数 *  * @param String *            sourceString * @return boolean */public static boolean isPositiveForInteger(String sourceString) {Pattern pattern = Pattern.compile("\\+{0,1}[0]\\.[1-9]*|\\+{0,1}[1-9]\\d*\\.\\d*");Matcher match = pattern.matcher(sourceString);if (isPositiveInteger(sourceString))return true;if (match.matches() && (Objects.equals(sourceString.substring(sourceString.indexOf(".") + 1), "00") || Objects.equals(sourceString.substring(sourceString.indexOf(".") + 1), "0"))) {double number = Double.parseDouble(sourceString);// 如果是数字,校验是否为大于1的正整数return (int) number % 1 == 0;} else {return false;}}

public static boolean isPositiveInteger(String orginal) {Pattern pattern = Pattern.compile("^\\+{0,1}[1-9]\\d*");Matcher match = pattern.matcher(orginal);return match.matches();}


0 0
原创粉丝点击