hannibal Posted March 5, 2008 Share Posted March 5, 2008 Hi I have some code whihc I am trying to exclude several characters: if (!preg_match("/^([a-z0-9._-](\+[a-z0-9])*)", $_POST["code"])){ // Raise error message = FAIL } else { // We are A OK. } In fact, all I want the user to be able to submit are "0-9a-z/_" (i.e. no spances, or dots or other special characters). I want to also esure that the first character is not a "/". But it always fails if I have "/" in my code and I cannot understand why. Any ideas anyone? Thanks in advance. H. Link to comment https://forums.phpfreaks.com/topic/94486-regex-help-only-numbers-and/ Share on other sites More sharing options...
effigy Posted March 5, 2008 Share Posted March 5, 2008 But it always fails if I have "/" in my code and I cannot understand why. Because you're using / as your delimiter. Either escape it, \/, or change the delimiter. %\A(?!/)[\w/]+\z% Link to comment https://forums.phpfreaks.com/topic/94486-regex-help-only-numbers-and/#findComment-483890 Share on other sites More sharing options...
hannibal Posted March 5, 2008 Author Share Posted March 5, 2008 Excellent - Works a charm, thank you very much. Doh! Can't believe it was as simple as changing the delimiter. Many many thanks. Link to comment https://forums.phpfreaks.com/topic/94486-regex-help-only-numbers-and/#findComment-483896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.