- Joined
- Jul 23, 2012
- Messages
- 201
- Reaction score
- 128
Here's basic introduction to php ctype functions, these function are used to validate string values if its correct type(alpha numeric, integer,string,etc).
Warning: You should always cast integer variables to string, because values between -125 and 256 are converted to their ASCII equivalent values.
Available functions
Result for this example would be: input is wrong
becouse ctype_lower only can contain only: a-z lower case only, no numbers
There are other functions to validate string like is_*(is_string,is_float,is_integer,is_numeric)
Warning: You should always cast integer variables to string, because values between -125 and 256 are converted to their ASCII equivalent values.
Example:
PHP:
<?php
$integer = 38;
ctype_digit($integer); // false, because ASCII 38 is '&'
is_numeric($integer); // true
Available functions
- ctype_alnum() : check for alphanumeric characters (A : Z, upper or lower case, 0-9, no special characters, punctuation, or other freaks).
- ctype_alpha() : check for alphabetical characters (A-Z, upper or lower case).
- ctype_cntrl() : check for control characters (things like \n, etc.).
- ctype_digit() : check for numeric characters (0-9, no decimal point, comma, etc.).
- ctype_graph() : check for visually printable characters (not control characters or space).
- ctype_lower() : check for lowercase characters (a-z lower case only, no numbers).
- ctype_print() : check for printable characters including control characters and space.
- ctype_punct() : check for punctuation type characters (no numbers, letters, or space). These include “special” characters like @&!#
- ctype_space() : check for white space characters (includes blanks and any control character that leaves a space on the page.
- ctype_upper() : check for uppercase characters (A-Z upper case only, no numbers or special characters).
- ctype_xdigit() : check for hex characters.
PHP:
<?php
if(ctype_lower('ABab10'))
{
echo 'all is okey!';
}
else
{
echo 'input is wrong';
}
Result for this example would be: input is wrong
becouse ctype_lower only can contain only: a-z lower case only, no numbers
There are other functions to validate string like is_*(is_string,is_float,is_integer,is_numeric)