Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Special Character Filter Function Problem

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
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?

Code:
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.

 
put it in the inverted character class you already have.

Chris.

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.
 
Escape it the same way you did with the hyphen:

PHP:
[^a-zA-Z0-9\-]

becomes

PHP:
[^a-zA-Z0-9\-\.]

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

PHP:
[^-a-zA-Z0-9\.]

will work fine.

Heaven doesn't want me, and Hell's afraid I'll take over!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top