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. Quote Link to comment 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% Quote Link to comment 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. Quote Link to comment 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.