开发者

JQuery Complex Client Side Validation

开发者 https://www.devze.com 2023-03-22 15:34 出处:网络
I\'m building an ASP.NET website to allow import of some tennis scores. I plan to have a line of textboxes for Player 1 and a line for Player 2 which allow for the scores to be input.

I'm building an ASP.NET website to allow import of some tennis scores. I plan to have a line of textboxes for Player 1 and a line for Player 2 which allow for the scores to be input.

My first task is to validate that the scores entered are valid. I could do this in code behind in an AJAX updatepanel so it happens seamlessly but I'm wondering if I could do it with client side validation and jquery. Is this more efficient or less efficient than taking up server time to handle it? The code would need to loop through the two textboxes for each set score and ensure that one of the players had 6 or 7 games and was 2 more games than the other player. If not it's either a tiebreak (in which case a pair of hidden tiebreak textboxes would need to be shown) or the score is not valid and th开发者_运维知识库e text boxes need to be restyled to highlight it.

Is this viable? If so I'd welcome any pointers to get me going. I've done little javascript/ jquery to date.


The question you should probably be asking is: "Is it secure to validate with javascript?". The problem is if say you have javascript built to say not allow a score above a certain point, that javascript can be manipulated on the client side to allow higher scores. The server side is still going to have to validate the score to make sure it is correct, so you will still require some server side validation. Javascript validation is really only to make things look pretty, it really isn't valuable when sending data to the server because javascript is easily manipulated with many tools. Firebug with Firefox for example makes it extremely easy to manipulate DOM variables to anything you want. Here is a link to JQuery validation plugin. Just remember if you are submitting the data to the server it must be revalidated to be completely sure nothing was manipulated on the client side to allow variables to be sent that were not within specifications.

However if data is not being stored on the server, only locally then there really isn't much to worry about.

http://plugins.jquery.com/project/validate

0

精彩评论

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