Textarea validation.

How can I validate a textarea is not empty? I use the code below, but it doesn't work well. Any suggestion? Thanks.

I use the following html code:
<form method="post" action="/EW/forms/form.jsp" id=formRequest name=Form onSubmit="return form_validator(this)">
<table>
<tr>
<td align="center" colspan="2"><textarea name="comments" rows="6" cols="48"> </textarea></td>
</tr>
</table>
</form>

My javascript:
function form_validator(theForm){
if (theForm.comments.value == ""){
               alert("Please provide details.");
      theForm.comments.focus();
      return (false);
      }           
    return (true);
    }
jen2483Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

devicCommented:
<textarea name="comments" rows="6" cols="48"> </textarea>

change to:

<textarea name="comments" rows="6" cols="48"></textarea>
0
GwynforWebCommented:
this checks for multiple spaces not just nothing

<script>
function form_validator(theForm){
if (/^ *$/.test(theForm.comments.value)){
               alert("Please provide details.");
     theForm.comments.focus();
     return (false);
     }          
    return (true);
    }
</script>

<form method="post" action="EW/forms/form.jsp" id="formRequest" name="Form"
onSubmit="return form_validator(this)">
  <table>
    <tr>
      <td align="center"><textarea name="comments" rows="6" cols="48"></textarea><input
      type="submit"></td>
    </tr>
  </table>
</form>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
devicCommented:
but not checks new lines, tabs, special symbols...

and what is very important, it doesn't check the spelling ;)
0
devicCommented:
@Gwyn

do you belive that I didn't answer the question?
have you no shame?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.