Php function check username
function checkUsername($username){
if(preg_match("/^[a-zA-Z0-9-_]+$/", $username)) {
if(strlen($username) >= 3){
if(empty($result)){
$result = 'success';
}
}else{
$result = 'invalid';
}
}else{
$result = 'invalid';
}
return $result;
}
<?php
if(checkUsername('YourUsername') == 'success'){
echo 'Username is correct!';
}else{
echo 'Invalid Username';
}
?>