I'm having trouble coming up with a regex capable of validating a US postcode (10,000 actually) that can read my entries in there current form. My program is using a validator from a UK postcode validator that I created. I am very stuck on this and am having trouble on figuring out how too proceed.
package postcodesort;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*
*/
public class ZipCodeValidator {
private static String regex = "^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$";
private static Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
public boolean isValid(String zipCode) {
Matcher matcher = pattern.matcher(zipCode);
return matcher.matches();
}
}
Below is a small example of the data in my text file.
"01","35005","AL","ADAMSVILLE",86.959727,33.588437,10616,0.002627
"05","72001","AR","ADONA",92.903325,35.046956,494,0.00021
"06","90804","CA","SIGNAL HILL",118.155187,33.782993,36092,0.001213
So I want it to read the first three sets of data. So "01","35006","AL" will be read and validated whilst the rest is ignored. So as long as it has two numbers, 5 numbers and two letters then it would be a validate postcode. I don't know how to make this happen.
Any and all help is appreciated!