Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
Hi, I am Sergio and I am creating a website at the moment. You can Register and Login there. Now to my question:

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

1. First Name
2. Last Name
3. Password
4. Email
5. 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
Posted
Updated 4-Jul-15 22:29pm
v2

That's mostly a matter of personal preference, and will be up to you - but there are two elements which are (or should be) restricted:
email: allow 256 characters. The local part of an email address (to the left of the '@') may be up to 64 characters long and the domain name may have a maximum of 253 characters – so in theory you need 318 characters, but the maximum of 256-character length of a forward or reverse path restricts the entire email address to be no more than 254 characters.

Password: You shouldn't store these. Instead, you should store a fixed sized hash value. Password Storage: How to do it.[^] explains the idea, but in C# rather than PHP - it's exactly the same pricincle though.

The other elements are just "whatever you feel like" - 20 characters, 50? As long as you check your user inputs before trying to submit to the DB, it's pretty much irrelevant once you get over 20 characters - but 50 is a better idea given the cost of storage these days.
 
Share this answer
 
v2
Comments
[no name] 5-Jul-15 4:27am    
Ok, thanks for your fast help!
OriginalGriff 5-Jul-15 4:31am    
You're welcome!
No size would be "perfect". The whole idea is wrong. The attribute maxlength is rarely used, by some good reasons. And it certainly should never be used for any of the fields you listed. They should not be limited in length; it would not make any sense. Default (when this attribute is missing) makes the number of characters unlimited; this is the only reasonable solution in your case.

Please see:
http://www.w3schools.com/tags/att_input_maxlength.asp[^],
http://www.w3schools.com/tags/tag_input.asp[^].

—SA
 
Share this answer
 
Comments
[no name] 5-Jul-15 4:28am    
Ok, thanks for helping!
Sergey Alexandrovich Kryukov 5-Jul-15 11:24am    
You are welcome.
Will you accept the answer formally? This is what you really need.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900