我必须像这样做验证如何实现它。
大型大写字母中应包含5个字母,后跟4个大写字母后跟1个大写字母(例如 - KLMNO5661P)
答案 0 :(得分:1)
您可以使用RegEX(正则表达式)检查格式
String s = "ABCDE1234F"; // get your editext value here
Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");
Matcher matcher = pattern.matcher(s);
// Check if pattern matches
if (matcher.matches()) {
Log.i("Matching","Yes");
}
[A-Z]{5} - match five literals which can be A to Z
[0-9]{4} - followed by 4 numbers 0 to 9
[A-Z]{1} - followed by one literal which can A to Z
答案 1 :(得分:0)
试试这个
final String pan_pattern = "(([A-Za-z]{5})([0-9]{4})([a-zA-Z]))";
checkpan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Pattern r = Pattern.compile(pan_pattern);
if (!regex_matcher(r, pan_number.getText().toString())) {
error = "Invalid PAN number";
}
}
});
<强> regex_matcher 强>
private boolean regex_matcher(Pattern pattern, String string) {
Matcher m = pattern.matcher(string);
return m.find() && (m.group(0) != null);
}