RedMaster Posted August 19, 2007 Share Posted August 19, 2007 Expression in question: $regexp1 = "^(([a-zA-Z\s]+([\s]?[\-]?[\s]?)?)+([a-zA-Z]*))+$"; So I picked up Regular Expression Editor (version 1.4.0.0) from Waterpoof software and I made the above expression in it and tested it against the string below and it worked okay. However when dropping it into the function below it aparently returns false. I hate to make this a broad question but maybe you may see something I haven't yet.. The pupose of this expression is to validate names which may contain spaces and/or hyphens but to not allow users to get carried away with excessive spaces or hyphens. I am very new to regular expression btw so no flames please. If you have any ideas I'd greatly appreciate it. String: cun lee pow-si- tu-do Function: function validateName($name){ $noodle1 = 0; $regexp1 = "^(([a-zA-Z\s]+([\s]?[\-]?[\s]?)?)+([a-zA-Z]*))+$"; if (eregi($regexp1, $name) == true) { $noodle1 = true; } else { $noodle1 = false; } return $noodle1; } Link to comment https://forums.phpfreaks.com/topic/65657-my-expression-works-in-regex-editor-but-not-in-php/ Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 for eregi use $regexp1 = '^(([a-zA-Z[:space:]]+([[:space:]]?[-]?[[:space:]]?)?)+([a-zA-Z]*))+$'; for Preg use $regexp1 ='/^(([a-zA-Z\s]+([\s]?[\-]?[\s]?)?)+([a-zA-Z]*))+$/i'; as a side note using eregi or adding i after the / delimitor on preg is case insensitive so you can remove the A-Z and just have the a-z example (this should work in replacment) function validateName($name) { return preg_match('/^(([a-z\s]+([\s]?[\-]?[\s]?)?)+([a-z]*))+$/si', $name); } Link to comment https://forums.phpfreaks.com/topic/65657-my-expression-works-in-regex-editor-but-not-in-php/#findComment-328152 Share on other sites More sharing options...
RedMaster Posted August 20, 2007 Author Share Posted August 20, 2007 Sweet, thanks MadTechie!! Your help is appreciated. Link to comment https://forums.phpfreaks.com/topic/65657-my-expression-works-in-regex-editor-but-not-in-php/#findComment-328574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.