在这里,我想为仅包含 0 到 6 个数字的字符串制作 regx。这个字符串包含 0 到 6 个这样的数字。
Example-1 : "010002030405" Valid String
这个字符串只包含 o 到 6 个数字,所以在这里我使用了这个 regx "[0-6]*"
。但是我想在这个字符串中验证的另一件事是,我只希望 0 在奇数位置 1-6 永远不会在奇数位置。0 可以放在奇数和偶数位置,但 1-6 只能放在偶数位置。
在这里,我给了你一些有效和无效的字符串示例
Valid : 000102000004
invalid : 0023015006
在这里我使用了这个代码请建议我或告诉我我必须在我的 regx 中更改什么以满足以下验证
1) String contains only 0-6 numbers nothing else.
2) 1-6 would be only even positions only they would not be at odd position ever, 0 would be odd and even position.
代码 :
public boolean isOptions(String input) {
String patternString = "[0-6]*";
Pattern pattern = Pattern.compile(patternString);
return pattern.matcher(input).matches();
}