File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes validate a textarea using regex Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "validate a textarea using regex" Watch "validate a textarea using regex" New topic
Author

validate a textarea using regex

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
I'm trying to validate the contents of a textarea using the following regex. I've had no trouble validating text fields using this regex but the textarea check always fails.
var chkPasswordQA = /^[A-Za-z]$/;
if (form.forgottenPasswordQuestion.value.search(chkPasswordQA) == -1) {
errmsg = errmsg+"\n"+(arrErrField.length+1)+". error ";
form action="go.jsp" method="post" name="form" onSubmit="return validate(this);"
textarea rows="3" cols="50" name="forgottenPasswordQuestion"></textarea>
[/CODE]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
try using match instead and I changed the regular expression slightly
var StrRE = /[^A-Za-z]/;
if(StrT.match(StrRE))alert('Error')
Eric
[ March 04, 2004: Message edited by: Eric Pascarello ]
 
 
subject: validate a textarea using regex
 
Threads others viewed
how to enable a textarea in javascript?
My form submit is called twice
acessing data of the textarea within the form of multipart type
problem enctype and charset
Double Byte Character "%" validation needed in Javascript
MyEclipse, The Clear Choice