Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15560
  • Last Modified:

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);
    }
0
jen2483
Asked:
jen2483
  • 3
1 Solution
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now