Bananas Development Blog: share your thoughts

Check if string is pure ascii in php

Auf der Basis von einem Eintrag aus der PHP Mailing List ([PHP] Check if string is pure ASCII?) habe ich eine Abfrage geschrieben die die Eingabe aus einem input Feld auf Valide Zeichen überprüft.

$validName = preg_match('/^[' . chr(65) . '-' . chr(90) . chr(97) . '-' . chr(122) . chr(48) . '-' . chr(57) . chr(95) . chr(45) .']+$/', $newFName);


Dieses preg_match gibt true wenn die Eingabe nur folgende Zeichen enhält:
a-z A-Z 0-9 - _


Damit hat man einen sicheren Weg die Eingabe zu filtern.

Die ASCII Codes kann man sich hier ansehen und somit das obige preg_match beliebig erweitern.

Banana
out

  • No comments

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Trackbacks / Pingbacks

  • No Trackbacks