I am learning JQuery, and I have checked out that JQUery has got a validation plugin. http://docs.jquery.com/Plugins/Validation#Validate_forms_like_you.27ve_never_been_validating_before.21
To use it, users have to include another script file in th开发者_运维百科e Head tag in HTML.
I am thinking if this will cause any code collisions to the codes in the validation plugin when more and more javascript files are included.Should I use JQuery to write myself new customed functions for checking data input from users
or use the JQuery data validation plugin?Please advise.
I would use the validation plugin if you're doing anything complex, or a lot of anything. It's not that heavy and has matured quite a bit. If it's overkill don't use it, if it fits your needs then do, it's an excellent plugin.
Main reasons:
- There are a lot of options
- There's a lot of community support/examples available to help.
- Depending on your server-side framework, there are lots of them that already have an integration with this in some way.
- It's already CDN hosted
The collisions I wouldn't worry about, only if you choose to include another .validate()
plugin, but this is conscious choice with anything javascript really, not something to worry about I would think.
I would suggest using the plugin. Of course, you should never rely solely on client validation - you should still validate the post in your server code.
I would give the plugin a try first, see if it meets your needs. I'd be very surprised if you have a problem with it conflicting with other libraries/scripts. The reason for this is because the plugin creates a closure by defining their functions and variables inside an anonymous function, so there won't be any collisions with other scripts on your page and globals won't get clobbered or any bad thing like that.
On a side note, you should also be validating on the server too.
精彩评论