Jump to content

Why Does Preg_match() Not Always Work?


vbsouthern
 Share

Recommended Posts

This code works if the user only enters 1 domain name. If the user enters many domain names then it stops working.

$pattern = '/[.]+(biz|com|edu|gov|info|net|org|tw|uk|us)$/ix';if (preg_match($pattern, "$message")) {  $validate = "Error";  $usermssg = "Domain names are not allowed in message.";}

Can anyone tell my why this does not work for multiple entries and what should I change to make it work for both?

Link to comment
Share on other sites

Because the $ sign at the end of the regex means "the end of the string must be here" - i.e. it won't match if there is anything after it.

Link to comment
Share on other sites

Just to point out, that regex isn't going to match a domain name, it's going to match any set of characters that ends in "biz", "com", "edu", "info", etc. That will match the string "I'm looking for info", which obviously isn't a domain name. It will not match the string "http://goatse.cx/", however, which it probably should.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...