Expression regular for address

Viewed 46

I need the correct regular expression for checking input text in HTML matching this format:

  • Initially, any number of letters (uppercase or lowercase) or white spaces may appear.
  • Then a comma followed by a blank space (, ) will appear.
  • After that, there must be a blank space.
  • Finally, after the preceding white space, 3 to 10 letters (without white spaces) will appear in parentheses.

Example: Street One, 13 (City)

I think I have to add anchors at the beginning and at the end, but I don't know how to join everything so that the complete regular expression remains.

<input type="text" placeholder="Your address city" **pattern="^\[a-z]i\s-\s[0-9]{2}\([a-z]{1,3})$"** required>
1 Answers

As per your sample input, following regex should work.

^(\w+\s?)+,{1}\s{1}\d{2}\s{1}\(\w{3,10}\)$

enter image description here

Related