Source Code : Match address regular expressions
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Match address regular expressions

public class MatchAddress {
public static void main(String args[]) {
isAddressValid("John Smith 888 Luck Street,NY 64332");
isAddressValid("John A. Smith 888 Luck Street, NY 64332-4453");
isAddressValid("John Allen Smith 888 Luck Street, NY 64332-4453");
isAddressValid("888 Luck Street, NY 64332");
isAddressValid("P.O. BOX 888 Luck Street, NY 64332-4453");
isAddressValid("John Allen Smith 888 Luck st., NY");
}
public static boolean isAddressValid(String addr) {
boolean retval = false;
String nameToken = "\p{Upper}(\p{Lower}+\s?)";
String namePattern = "(" + nameToken + "){2,3}";
String zipCodePattern = "\d{5}(-\d{4})?";
String addressPattern = "^" + namePattern + "\w+ .*, \w+ "
+ zipCodePattern + "$";
retval = addr.matches(addressPattern);
String msg = "NO MATCH
pattern:
" + addr + "
regexLength:
"
+ addressPattern;
if (retval) {
msg = "MATCH
pattern:
" + addr + "
regexLength:
"
+ addressPattern;
}
System.out.println(msg + "
");
return retval;
}
}
Thank with us