Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the better way of validating user input, DB Constraints or Javascript?

I want to validate user input on a Web Form, like valid numbers, date etc. Which one is the better way to validate, using Javascript functions or using Constraints in SQL Server?

I want to reduce the code as much as possible and want to use most of the power of SQL Server itself.

like image 888
RKh Avatar asked Dec 06 '22 19:12

RKh


1 Answers

You must do both. Client-side validation to prevent all but sensible input, and server side (including in code prior to hitting the database), to prevent more malicious attempts at doing things.

So, in ASP.NET, at the very least, use the built-in validator controls, which emit JavaScript if you want them to. Then, in server-side events that occur when, say, a submit button is clicked, check Page.IsValid to ensure the JavaScript was not bypassed. Next, ensure you are using parameterized queries to prevent SQL injection. And, lastly, always use constraints to ensure data correctness if all else fails.

like image 60
Sumo Avatar answered Dec 10 '22 11:12

Sumo