Jump to content

[SOLVED] removing non-standard characters


billo

Recommended Posts

Can I use a regex function to check a string and remove any character that you wouldn't find on a standard western keyboard?

 

I tried preg function but it fails to detect some odd unprintable characters when they are pasted into the textbox:

 

if(preg_match_all("/[^a-z0-9 \$_.,'()?!:\/;\&\#…\%\–]/i",$fldVal,$invalid))

 

Thanks in advance for any suggestions...

Link to comment
https://forums.phpfreaks.com/topic/174649-solved-removing-non-standard-characters/
Share on other sites

thanks, but this doesn't catch accents as in crêpes or café

any thoughts on how to weed them out?

 

just to be clear, I want to check the text and chuck it out if I find anything other than A to Z, numbers and standard punctuation marks. So if someone tries to sneak in any weird character (pick one, lets say an angstrom Å=ångström), then I want to reject the text.

thanks again

It does catch accents

 

$fldVals = array("crêpes or café","test","Å=ångström");
foreach($fldVals as $fldVal)
{
echo $fldVal;
if (preg_match('/^[\20-\x7E]+$/', $fldVal))
{
	echo ": valid<br>\n";
}else{
	echo ": invalid<br>\n";
}
}

 

returns

crêpes or café: invalid<br>

test: valid<br>

Å=ångström: invalid<br>

 

as test was the only one with standard characters, its the only valid one

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.