yoursurrogategod Posted June 20, 2013 Share Posted June 20, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279393-weird-regex-warning/ Share on other sites More sharing options...
requinix Posted June 20, 2013 Share Posted June 20, 2013 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-. Quote Link to comment https://forums.phpfreaks.com/topic/279393-weird-regex-warning/#findComment-1437079 Share on other sites More sharing options...
ragax Posted July 26, 2013 Share Posted July 26, 2013 You also don't need to capture the last part of the match. A starting point to modify the regex would be elseif( ! preg_match("~^[A-Z]'?[- a-zA-Z](?: [a-zA-Z])*$~", $_POST['lastNameForm']) ) but as requinix said, the match criteria are way loose. Quote Link to comment https://forums.phpfreaks.com/topic/279393-weird-regex-warning/#findComment-1442215 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.