开发者

data validation - which is faster?

prob silly question:

I have a list of 10 emails on the page and inserting a new one. I want to check, if it doesn't duplicate, so which is faster: to do jquery string comparison on the client side, or check that with stored procedure in the C开发者_如何学C# code behind.. Is it a correct to say, that checking in DB is a right way to do it, and checking in the client side is a fast way..?


The client-side check is only for the sake of the user, So that he doesnt have to perform a whole request and see a new page pop up only to tell data is wrong.

Validation on server is mandatory cause user can manipulate javascript code on client.


You should do validation at both sides. On the client to give the user a responsive quick experience. The same validation should occur on the server as well. Since if the user has JavaScript disabled you need to validate the input. As no user input should be trusted. Ever.


It's not quite correct to say that.

You need to do it in the DB, because the JavaScript may not be executed. But, offseting some of the work to the JavaScript will reduce the load for your DB as, in general, it won't need to do the work (for that list of 10).

So, basically, you do it in two places. In the DB because it must be done; (indeed, you can enforce this anyway with a unique index), and in the JavaScript because it is a pleasent experience to do it there, and with the hope that it may save you some processing on the server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜