I need to generate regex to validate state as Tamilnadu based on Pincode validation
Regex which I tried fails at some point
String regex = "^[60-64]{2}{0-9}{4}$";
Ref the Tamil Nadu Pincode info link. It starts with 60-64 as the first two digits, the next 4 digits as 0-9 numbers. It must have six digits.
the code
public boolean isHomeState(String state, String zipcode) {
if (isValidZipCode(zipcode)) {
// ...
}
return true;
}
private boolean isValidZipCode(String zipcode) {
String regex = "^[60-64]{2}{0-9}{4}$";
Pattern p = Pattern.compile(regex);
// If the pin code is empty
// return false
if (zipcode == null) {
return false;
}
Matcher m = p.matcher(zipcode);
return m.matches();
}