I want to check the username to contain only letters. If it doesn't contain any letters, the registration I want to fail. Is it good to use preg_match? Now if I input for username: a1, also filling the password, confirm password and type fields the registration is successful.
form.php
if (isset($_POST['submit'])){
    /* if the username is alphabetic */
    if (ctype_alpha(str_replace(' ', '', $username)) === false &&!empty($username) ) {
        $errors[] = 'Userame must contain letters and spaces only';
    }
    /* if passwords match */
    if((!empty($password) && !empty($repassword)) && ($password != $repassword)){
        echo "Passwords do not match.";
    }
    if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['type'])){
            $sql = "INSERT INTO users (username, password, type) VALUES ('$username', '$password', '$type')";
            $result = mysql_query($sql);
            echo 'Successful Registration.';
    }
    else{
        echo 'Please fill all the fields.';
    }
} 
 
    