Jump to content

Weird regex warning...


yoursurrogategod

Recommended Posts

Hi.

 

I have this bit of code:

 

 elseif(!preg_match("^[A-Z]'?[- a-zA-Z]( [a-zA-Z])*$", $_POST['lastNameForm']))

 

Now, when I run it, I get this error:

Warning: preg_match(): No ending delimiter '^' found in C:\xampp\htdocs\user_personal_info.php on line 21

 

Warning: preg_match(): No ending delimiter '^' found in C:\xampp\htdocs\user_personal_info.php on line 30

 

Why am I getting this error? I want to check whether the user correctly entered only letters (an apostrophe is permissible as well) for first/lastname.

Link to comment
https://forums.phpfreaks.com/topic/279393-weird-regex-warning/
Share on other sites

Unlike in POSIX (ereg* functions), PCRE (preg*) regexes need delimiters around the expression, mostly to separate it from any flags (case-insensitivity and such).

 

Often you can simply add a character at the front and back (making sure to escape it if it's used in the expression) with / and # being the most common.

/^[A-Z]'?[- a-zA-Z]( [a-zA-Z])*$/
By the way your expression seems a bit too loose: it'll accept names like A' and A-.
Link to comment
https://forums.phpfreaks.com/topic/279393-weird-regex-warning/#findComment-1437079
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.