Jump to content

[SOLVED] removing non-standard characters


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.