| |
|
Ctype_alnum to check alphanumeric characters |
ctype_alnum is a PHP filter function checks presence of all alphanumeric characters. It allows a to z characters and 0 to 9 numbers. Any thing other than this if present then it return FALSE.
This is a good function to check data coming from insecure sources like user input data. Before storing or processing such data we can use this filter to match our requirement. Here is the syntax
bool ctype_alnum($text)
Now let us try with some examples.
$var="10af4g4";
if(ctype_alnum($var)){
echo " This is alphanumeric ";
}else{ echo "this is not alphanumeric";}
You can change the value of the variable $var and see the result. Decimal points are not allowed ( False ) in ctype_alnum.
We can check the form data input by users directly by using ctype_alnum function. Here is one example.
if(ctype_alnum($_POST['var'])){
echo " This is alphanumeric ";
}else{ echo "this is not alphanumeric";}
Here if you want to check only numeric numbers then better to use is_numeric() function.
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
|
|