Search code examples
mysqlsizefieldtype

Is it possible to limit the size of text-type field in mySQL?


I know that it can be done with varchar, char and others. but, is it possible with text?


Solution

  • TEXT itself can't be limited, but you can limit - through the code that's handling then passing it to the PHP - how much the user can enter. For example, in javascript, if "str.length>X" you could alert "Stop being so long-winded," rather than posting to the PHP handling page - that is, of course, very easily defeated. However, couple that with a check in the php before putting it into the database, and you should be good.