if (preg_match('/^[A-Za-z]{1}[A-Za-z0-9]{5,31}$/', "moo123")) { echo 'succeeded'; } else { echo 'failed'; }