Forum : How can I check that a data value is alphanumeric?
Brief description  about Online courses   join in Online courses
View Balu  Prasad 's Profile

How can I check that a data value is alphanumeric?

How can I check that a data value is alphanumeric?????
Asked by Balu Prasad | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Balu,
There are various ways to do this, and people commonly do this with a regular expression of some description.

However if you don't want to get involved with those or find them confusing, as usual with PHP there is a function lurking around to help you achieve your desired result.

You can easily validate specific to the curernt locale setting with the ctype_alpha function, one of the character type functions added to PHP in version 4.3 which works like this:

<?php
$formvalue = "am I alphanumeric or not";
if(ctype_alpha($formvalue)) { echo "Yes I am!"; } else { echo "No I'm not!"; }
?>
In this case printing "No I'm not!" because $formvalue contains spaces.
Mar 17, 2010