I have a forum and visitors can register user names with more than 20 letters, how can I deny those visitors to register with a (long) user names?
the registration form is using PHP language.
thanks,
You can add a maxlength
attribute to your HTML form as a first-step measure.
<input type="text" name="username" maxlength="20" />
On the PHP side, you can use strlen
to check the length of your passed parameter.
Make a condition.
if (strlen($_POST['whatever-username-field']) > 20){
// not allowed to proceed
}
Use strlen()
function which is supposed to mean string length like this:
if(strlen($username) > 20) {echo "You can not enter more than 20 characters";}
Or in your html form use the max length attribute. like:
Username: <input type="text" name="usrname" maxlength="20" />