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.

Discuss this tutorial at forum


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
Validating Date: Checking if date exist
Email address validation in a form
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?














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.