Hi, I am Sergio and I am creating a website at the moment. You can Register and Login there. Now to my question:

Witch maxlength values should I take for the different input fields, for example:

  • First Name
  • Last Name
  • Password
  • Email
  • Username

I don't know the perfect size for the fields and would be very happy if somebody could help me

best regards,
Sergio Wagenleitner

Hi Sergio

Max length for fields will depend purely on what you plan to store in them and whether we are talking about, after creating many different forms over time you get to a feeling for these things. Here are the sizes that I use:

First Name & Last Name - 100chars - Some people have long names!
Password - 100 chars - I store a hash for the password so has to be long
Email - 254 chars - That is the max length for an email
Username - 20 chars,
Telephone numbers - 30 chars - should cover all international area codes & extensions

I may be a bit exessive in the lengths but have found that I hate to redo database design for silly reasons like someone's double barrel first name or last name being way to long.

Hope this helps, good luck with the programming!

Yh I agree with andrevanzuydam, some people has very long names (both first and last ones). So 100 chars will be okay. But one thing I can add is that, if you know the hashing method you will use on the passwords, set the password length to the hash length.

md5() gives 32 chars
hash('sha256') gives 64 chars

I hope it helped.

Member Avatar

Have a look at some releases of open source software too, e.g. phpBB - have a look at the DB created. The length of the telephone number may be less if you just want to collect mobile or domestic numbers. Anybody who has an email address larger than about 40 chars may be deranged, however I usually allow 75 chars.