I currently have this code below which validates username length only. If none entered it will show error message, if less than 3 characters entered show error message. I want to add an if/else statement that if the user enters special characters like !@#$%^&*()+=/? etc... the only special character is allowed is underscore (_) and hypen (-)... Help me how.
thanks
here's the code i have:
<?php
$serror="";
if (isset($_POST['submit'])) {              
    $username=$_POST['username'];
    $lengt = strlen($username);
    if($lengt == 0){
        $serror=" Please enter account username ";
    }
    else{
        if($lengt < 3 ){            
            $serror=" Please enter valid account username ";
        }
    }
    if($serror==""){
        ob_start();
        echo "Success";
        header("Location:progress.php?username=$username");
        exit;
        ob_end_flush();
    }
    else{}              
}
?>