Ctype – Built-in Form Input Validation Functions in PHP

In previous article you saw how these functions could be used for simply complex form input validation. Ctype_* provide checking for these types of characters:

ctype_alnum -- Check for alphanumeric character(s)
ctype_alpha -- Check for alphabetic character(s)
ctype_cntrl -- Check for control character(s)
ctype_digit -- Check for numeric character(s)
ctype_graph -- Check for any printable character(s) except space
ctype_lower -- Check for lowercase character(s)
ctype_print -- Check for printable character(s)
ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character
ctype_space -- Check for whitespace character(s)
ctype_upper -- Check for uppercase character(s)
ctype_xdigit -- Check for character(s) representing a hexadecimal digit

ctype_* function returns True or False. If every character satisfies requested criteria then it returns True. Your current locale will affect the behaviors of these functions. For setting locale check for setlocale().

Combine these functions with PHP str_replace() function and you are almost free with your form validation problems.

Comments are open for an year period. Please, write here on Facebook page.