Sandeep is correct.
there are various ways to do it.
if you want to validate your user input using javascript heres a basic function
<script type="text/javascript">
function validate()
{
if (document.getElementById('txt').value.length > 50)
{
alert("error message"); return false
}
}
</script>
<input type="text" id="txt" />
<input button="submit" onclick="return validate();" />