Hola 
Anarninquë 
A ver si te sirve este ejemplo: 
 Código PHP:
    <html>
<head>
<script type="text/javascript">
function validar(e,txt) {
  tecla = (document.all) ? e.keyCode : e.which;
  if (tecla==8) return;
  palabra = txt.split(' ');
  return (palabra.length<4)
}
</script>
</head>
<body>
<input type="text" onkeypress="return validar(event,this.value)" />
</body>
</html> 
   
  Saludos,