Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
RegEx for CITY: we will require that there be 2 alpha characters AND no numeric characters.

Regex for STREET :have 2 consecutive alpha characters,
or a number and an alpha,
or a number and a number,
or an alpha and a string

What I have tried:

Reg Ex for City and Street


to have 2 consecutive alpha characters
Posted
Updated 30-Aug-17 21:41pm

1 solution

For city, try:
^[a-zA-Z]{2,}$
But ... "St.Louis"? "New York"? You might want to expand your specification.
Similarly, streets are fraught with problems: spaces are very common, "42nd St." is very possible, and so forth. You probably don't want to use a Regex for either of these - there are too many "edge cases" which will frustrate users trying to enter the data they know is correct but your rules don't accept.

For cities, I'd use a list (or free text), for streets I'd allow free text.
 
Share this answer
 
Comments
Member 12613458 31-Aug-17 6:25am    
How for this one?
have 2 consecutive alpha characters,
or a number and an alpha,
or a number and a number,
or an alpha and a string

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900