Since the javascript lives in the browser, it's fairly easy for a user to check your source code and bypass any js validation mechanisms. That's why it's usually done server-side.
It's a pain but I usually implement validation both in javascript and on the server, that way "normal" users will have a quick response, and "hackers" will be kept out of the system. Unfortunately I think that's the way you need to go if you want both good user experience and good security.
To answer your question, to my knowledge there's no common library that can be used both on the client side and the server side.
PS. remember JavaScript is not Java ! :-)
http://en.wikipedia.org/wiki/JavaScript#JavaScript_and_Java