I am trying to figure out the reg ex khổng lồ match a street address. The format of the street address must be 2 or 3 digit number followed by a text string of the street name then ending with "Street" or "Road".

Bạn đang xem: Php

So a valid address can be:

12 Fake Street12 nhái Road123 fake Street123 giả Road

Invalid address would be:

1 fake Street1 kém chất lượng Road1234 nhái Street1234 kém chất lượng Road

preg_match("/^<0-9>2,3 * *(Street|Road)$/", $_POST<"street">)I"ve sầu tried multiple ways khổng lồ approach this & can"t get the digits in lớn work correctly.If I try /^<0-9>2,3$/ it works by itself but when I add in the string expressions, it messes it up. Also using that formula without ^ or $, it"ll validate any amount of digits beyond 3 digits long. So 1234, 12345, etc will work.

php regex
edited Oct 27 "13 at 17:15

27.4k1616 gold badges9797 silver badges150150 bronze badges
asked Oct 27 "13 at 17:11

14911 gold badge44 silver badges1414 bronze badges
Add a comment |

1 Answer 1

Active Oldest Votes
You don"t have correct regex to lớn match street name that comes after first digits since will match single alphabet only

Use this regex:

preg_match("/^<0-9>2,3 ++ +(Street|Road)$/", $_POST<"street">);Difference is + instead of

PS: Also changes lớn + instead of * since at least 1 space is needed between these components.

Xem thêm: Cách Bỏ Bú Cho Trẻ - Cách Cai Sữa Cho Bé: Mẹo Cai Sữa Đêm Cho Trẻ 1

answered Oct 27 "13 at 17:15

664k5959 gold badges468468 silver badges546546 bronze badges
Add a comment |

Your Answer

Thanks for contributing an answer lớn Staông chồng Overflow!

Please be sure to lớn answer the question. Provide details và chia sẻ your research!

But avoid

Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; baông chồng them up with references or personal experience.

To learn more, see our tips on writing great answers.

Xem thêm: Hiểu Tường Tận Về Bệnh Tiểu Buốt Ở Phụ Nữ, Nguyên Nhân Dẫn Đến Tiểu Buốt Ở Nữ

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using E-Mail and Password

Post as a guest

E-Mail Required, but never shown

Post as a guest

Thư điện tử

Required, but never shown

Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree to lớn our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged php regex or ask your own question.

The Overflow Blog
Featured on Meta
How to validate an tin nhắn address in JavaScript
How can I prsự kiện SQL injection in PHP?
How to lớn validate an gmail address using a regular expression?
How do I make a redirect in PHP?
How do I get PHP.. errors khổng lồ display?
How lớn get the client IPhường address in PHP.
How bởi vì you parse và process HTML/XML in PHP?
How do you use bcrypt for hashing passwords in PHP?
How does PHP 'foreach' actually work?
PHP Regular expression lớn kiểm tra 3 digits followed by alpha
Hot Network Questions more hot questions

Question feed
Subscribe to lớn RSS
Question feed To subscribe to this RSS feed, copy and paste this URL inkhổng lồ your RSS reader.


Staông xã Overflow
Staông xã Exchange Network
site thiết kế / logo sản phẩm © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.5.27.39382

Staông chồng Overflow works best with JavaScript enabled

Your privacy

By clicking “Accept all cookies”, you agree Staông xã Exchange can store cookies on your device & discchiến bại information in accordance with our Cookie Policy.

Chuyên mục: