Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Special Character Filter Function Problem

Special Character Filter Function Problem

Special Character Filter Function Problem

I have the following function called within a large PHP script. All this function does, is it checks to see if any special character(s) have been submitted in a form. If a special character has been submitted, than an error message is sent to the user to fix their form entry. Right now, this script works find and it filters ALL special characters. I would like to allow the the period symbol to come through the from while continuing to block all other characters. Can someone help with this?


function check_domain($dname) {
global $errormsg, $text_17, $text_18, $text_19, $minlength, $maxlength, $reserved;
// Check if special chars are in there
	if(ereg("[^a-zA-Z0-9\-]",$dname)) { 
		$errormsg = "$text_19<br>";
	return $errormsg;

Thanks for your time.

RE: Special Character Filter Function Problem

put it in the inverted character class you already have.


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Special Character Filter Function Problem

Escape it the same way you did with the hyphen:

CODE --> php



CODE --> php


Another thing is that you don't need to escape the hyphen if you place it at the start:

CODE --> php


will work fine.

Heaven doesn't want me, and Hell's afraid I'll take over!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close