SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.
Check a string for only alphabetic characters by ctype_alpha function



Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Handling drop down list box with multiple selection options using array
Validating Date: Checking if date exist
Email address validation in a form
Email validation using Ajax & PHP
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?
















Join Our Email List
Email:  
For Email Newsletters you can trust
Form handling
PHP Sections