Server side validation is always better than client side validation. Client side validation uses javascript which can be turned of in the browser.
You can put the client side validation script into an external javascript file, your syntax looks correct.