Background
I'm looking to put together a single page web application with many form inputs. I've run into issues with other web pages where there is an ugly SQL error sent to the user if the maxlength
constraint of the field in the table was violated. I'd like to know how to manage this type of validation.
Questions
Should I put the effort into making sure that the HTML form input is limited in size for every input field (as opposed to targeting significant fields)?
Should the
maxlength
of the input field be tied programmatically to the constraints of database fields (through a query of the database system tables) or would this be unrealistic?
I'm looking for both what is best practice and what is maintainable (I don't want to have to do a lot of extra work if the database design changes). Is it easier just to decode the SQL error post-submit and inform the user?
Related Questions
- max length validation check - More specific to what length to set fields at. I'm more interested in the broader question of applying the length.
- When and how much should we validate input when working with (C)AP storage? - Probably the most similar. It is about validation in general.
- Data input validation - Where? How much? [closed] - Broadly touches on some principles including stating:
use of additional validation like "between 6 and 20 characters" less frequent, as this increases maintenance work on changes