Hello. I'm new to php and i'm having one or two problems attempting to validate the fields in a form. I wan't to make sure that no characters such as $£%£^ or numbers are used in the username field when the user attempts to sign up. I also want to make sure that the user picks a username that is more than 6 characters in length but less than 10.
I'm sure this is simple enough to resolve as i am of little php experience i was wondering if maybe one of you could help a little with finding the error(s). The code is missing one or two elements to get it to work properly. This is the excerpt from the code which is causing the problem. I keep getting an error on line 41 stating "Call to undefined function: ctype_alpha()"
<?
include 'db.php';
// Define post fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];
/* Let's strip some slashes in case the user entered
any escaped characters. */
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);
/* This is the Error Checking Validation Fields. This is where the problem lies */
if((!$first_name) || (!$last_name) || (!$email_address) || (!$username) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
if(!(ctype_alpha($username)) || ($username == "") || ($username == NULL) || (strlen($username) < 5) || (strlen($username) > 15)){
echo "You have an invalid username. It must be between 5 and 15 characters and can only contains letters a-zA-Z. <br />";
}
include 'join_form.html';
exit();
}
i also have or two other problems with the form which i may ask as well but the validation is the important thing at the moment. Thanks very much to anybody who can help me in this matter.