PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have some form validation done, but it's not very good. How do i make sure that users can only use a-z, A-Z, 0-9. Would this help make sure my site is more secure. (there for users would not be able to use special characters)
// check that username is 5 characters or more
$username = $_POST['username'];
if (strlen($username) > 4){
}
else {
die
//email validation - i got this from a script
$email = $_POST['email'];
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
}
else {
die
how can i make sure that the $username only can have a-z, A-Z, 0-9
$status = "OK"; // setting the flag for form validation
$msg=""; // error message string is blank
function check_field2($username)
{
if(!preg_match("/[^0-9\ ]+$/",$username))
return TRUE;
else
return FALSE;
if(!check_field2($username))
{
$msg .="<center>Please enter a number for username</center><BR>";
$status="NOT OK";
}
}
You could do it that either way it prevents from SQL insertion, which is defintley an important thing to prevent!!!!! Which was one of the things the other posts requested..