speedy33417 Posted March 20, 2010 Share Posted March 20, 2010 I have to validate a user input to being a valid HTML title tag text. Basically whatever the user would input here would be used as the Title for a specific web page. I would like to allow all characters that can be used for this purpose. I'm no good with Regex. I use the following code to validate user entry where only letters and numbers validate. How would I modify this script to use for the above example? if (ereg("[^a-zA-Z0-9]", $userInput)) Quote Link to comment Share on other sites More sharing options...
newbtophp Posted March 20, 2010 Share Posted March 20, 2010 if (preg_match("/([a-z0-9\- ]*)/i", $userInput)) Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 22, 2010 Share Posted March 22, 2010 As long as you encode the text with htmlentities() or similar, it should be valid. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 23, 2010 Share Posted March 23, 2010 ctype probably would work best in this situation... if(ctype_alnum($userInput)){ echo 'Good!'; }else{ echo 'Bad!'; } Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 23, 2010 Share Posted March 23, 2010 ctype probably would work best in this situation... He's not looking to accept alphanumeric characters only: I would like to allow all characters that can be used for this purpose. 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.