note 39855 deleted from function.strspn by nlopess
| From: | nlopess@php.net | Date: | Tue, 11 Oct 2005 17:28:43 +0000 |
| Subject: | note 39855 deleted from function.strspn by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96843@lists.php.net to get a copy of this message | ||
Note Submitter: ronq dot NOSPAM at arnet dot com dot ar
----
You can validate a text with this function, restricting the allowed characters of the input, I use
it to avoid malicious or wrong form submissions. This is a first issue on security, to be sure that
the data you get is safe to work with.
<?php
function valid($str) {
$validlength=10;
$validmask="abcdefghijklmnopqrstuvwxyz0123456789_-";
$str=strtolower($str);
if (strspn($str, $validmask) == strlen($str) && $validlength >= strlen($str)) {
return true;
} else {
return false;
}
}
?>