Warning: preg_match() [function.preg-match]: No ending delimiter '^' found Warning: preg_match() [function.preg-match]: No ending delimiter '^' found wordpress wordpress

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found


/ is missing. preg_match('/pattern/',$string);

preg_match("/^http:\/\/[-0-9a-z\._]+.*$/i", trim( $url ));


As it has been said in other answers, you have to use delimiters arround the regex. You have also the possibility to use another character than / to avoid escaping them:

return preg_match("~^http://[-0-9a-z._]+.*$~i", trim( $url ));

And you could use \w that is shortcut of [a-zA-Z0-9_]:

return preg_match("~^http://[-\w.]+.*$~", trim( $url ));


Your regex needs a delimiter around it, e.g. /

 return preg_match("/^http:\/\/[-0-9a-z\._]+.*$/i", trim( $url ));

This delimiter can be different characters but it must be the same before and after your regex. You could e.g. also do this

~regex~

or

#regex#

The advantage is, use a delimiter that you don't have inside the regex. If you use / as delimiter and want to match "/" you have to escape it inside the regex ///, if you change the delimiter you could do #/# to match a "/"