Is adding maximum character restrictions a good idea on form fields which store data in a database?
I already have minimum character limit, but was wondering is also adding a max开发者_如何学Cimum a good idea?
For example; I have a post topic form which creates a forum topic (and stores the info in a MySQL
database - the data type for the columns which are effected is text
) - I have a minimum character limit for both the topic title and topic body, but I've seen on several other sites they have a maximum character limit aswell?
Is there any specific reason which in my situation it would be a bad idea?, why do sites commonly have this restriction (other then the obvious - could it effect functionality?) and if so what would be a typical/average maximum character limit for a topic title and a topic body (is there a general rule of thumb to determine this)?
Thank You.
The biggest reason I can think of as to setting a maximum character limit is because if you insert data into a MySQL database and the input is larger than the maximum length the column supports, the data is simply truncated with no error.
You can set the limits on the text field in HTML, but a user with the right tools can remove this restriction, so for very important data, you may want to check the length on the server side and make sure it can fit where it is going.
For your situation, I guess the other reason would be to prevent a user from creating a thread subject that is extremely long.
The title of your post here is good, but it may not be good if you were to add much more to it i.e.: Is adding maximum character restrictions a good idea on form fields which store data in a database because I am not doing it on my site and think I should, but don't know if I should or not
. So I think it serves as a limitation in that sense too. Also, since your display may truncate the subject to a certain length in order to prevent breaking a layout or looking bad, it helps the user come up with a concise subject.
You may look at some free forum software to see what limits they put on the subjects, a reasonable limit seems like maybe 128 characters. Your subject is 100.
As for limiting the body, 65,635 bytes is pretty reasonable. On forums people who make really long posts tend to break them up into multiple posts because of limitations imposed.
精彩评论