Javascript would certainly perform client-side validation of user input, but it should not be considered enough to prevent illegal input from reaching your server.
For example, it would be a simple matter for me to grab your form, save it locally on my machine, remove the javascript validation and submit whatever I wanted to your server.
Have a look at some of the various frameworks available, such as Struts or Spring. It will be helpful to learn about Regular Expressions, as they are powerful ways to validation, and are usable on the server side.
Regards.