public class ZipCodeValidator
{
public boolean validate(String zip)
{
String zipCodePattern = "\\d{5}((-)?\\d{4})?";
return zip.matches(zipCodePattern);
}
public static void main(String arg[])
{
ZipCodeValidator zipCodeValidate = new ZipCodeValidator();
boolean retVal = zipCodeValidate.validate("67652-5651");
if(retVal)
System.out.println("valid zip code found");
else
System.out.println("invalid zip code found");
}
}
No comments:
Post a Comment