codice:
  function checkMaxLen( __hTextArea, __maxLength )
  {
    if ( __hTextArea.value.length > __maxLength )
    {
      alert( "Il campo " + __hTextArea.name + " può contenere solo " + __maxLength + " caratteri" );
      __hTextArea.value = __hTextArea.value.substring( 0, __maxLength );

      __hTextArea.select( );
      __hTextArea.focus( );

      return false;
    }

    return true;
  }
<form...

<textarea onchange="checkMaxLen( this, 400 );" onkeydown="checkMaxLen( this, 400 );">