Author Topic: User input validation for HTML title tag  (Read 737 times)

0 Members and 1 Guest are viewing this topic.

Offline speedy33417Topic starter

  • Enthusiast
  • Posts: 80
    • View Profile
User input validation for HTML title tag
« on: March 20, 2010, 05:09:26 PM »
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))

Offline newbtophp

  • Devotee
  • Posts: 624
  • PHPFreaks Fan!
    • View Profile
Re: User input validation for HTML title tag
« Reply #1 on: March 20, 2010, 07:26:13 PM »
if (preg_match("/([a-z0-9\- ]*)/i"$userInput))
Quote from: AngelicS
You DO NOT have to say thank you =)
I find it meaningless ^^

Offline thebadbad

  • Addict
  • Posts: 1,610
  • Gender: Male
  • $me = str_replace($question, $answer, $post);
    • View Profile
Re: User input validation for HTML title tag
« Reply #2 on: March 22, 2010, 03:23:06 AM »
As long as you encode the text with htmlentities() or similar, it should be valid.

Online The Little Guy

  • Freak!
  • Posts: 6,100
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: User input validation for HTML title tag
« Reply #3 on: March 23, 2010, 12:38:42 AM »
ctype() probably would work best in this situation...

if(ctype_alnum($userInput)){
    echo 
'Good!';
}else{
    echo 
'Bad!';
}
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline thebadbad

  • Addict
  • Posts: 1,610
  • Gender: Male
  • $me = str_replace($question, $answer, $post);
    • View Profile
Re: User input validation for HTML title tag
« Reply #4 on: March 23, 2010, 05:13:33 AM »
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.