I want my regex to be able to handle 123 Rock Rd or 444 Blue Bird Ln.
Here is my attempt:
The output keeps generating invalid input when I enter 444 Blue Bird Ln:Code://accept strings that are in the format of 123 Rock Rd or 444 Blue Bird Ln (not case sensitive)
public static boolean validateAddr(String address)
{
return address.matches("\\d+ \\s+ [a-zA-Z]+ | ([a-zA-Z]+ \\s+ [a-zA-Z]+) \\s+ [a-zA-Z]+");
}
Code:
//ask the user for the address until they enter valid input
do
{
System.out.println("Enter the address: ");
addr = in.nextLine();
if(ValidateInput.validateAddr(addr))
addrbk.setAddress(addr);
else
System.out.println("Invalid input. \n");
}while(!ValidateInput.validateAddr(addr));
