Monday, May 17, 2010

PHP Validate Alphanumeric Characters

Validate alphanumeric characters use PHP


HTML Code:
Copy this code and save as form.php

<form action="validate.php" method="post">
<input name="name" id="name" type="text"/>
<input name="submit" type="submit" value="Validate">
</form>

PHP Code:
Copy this code and save as validate.php

<?
$name = $_REQUEST['name'];
if(!ereg('^[[:alnum:]]+$',$name)){
echo "Not a alphanumeric characters";
} else {
echo "Valid alphanumeric characters";
}
?>



No comments: