472,328 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

TextArea Validation

I need to validate my TextArea as follows:

1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS
2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW

I need some kind of a JS validation for the same. I have tried using hard wrap
but that doesnt help completely.

Any help in this matter would be very much appreciated!
Thanks!
S Kulkarni
Jul 20 '05 #1
3 32228
ku********@hotmail.com (Sunil Kulkarni) writes:
I need to validate my TextArea as follows:

1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS
I assume you mean rows :)
2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW

I need some kind of a JS validation for the same. I have tried using
hard wrap but that doesnt help completely.
A regular expression should be able to match zero to five lines of
zero to 65 characters, if you define the lines to be separated by
newlines ("\n").

If you want to look at automatic line wrapping, and count lines as
they are displayed, it gets ugly fast, but with some assumptions,
it should be manageable.

So, let's define a line to be up to 65 characters followed by a
newline characters, or just 65 characters followed by a newline, and
we want to check that a string contains at most 5 lines.

The final line can be up to 65 characters without being followed by a
newline.

A suitable regular expression is:
/^(.{0,65}\n|.{65}){0,4}.{0,65}\n?$/

However, the input of a textarea might not use a single character for
newlines. Both Opera and IE ends their lines with "\x0d\x0a"
(Carrige Return + newline, DOS EOL), where Mozilla uses "\x0a" (Just
newline, Typical Unix EOL). Maybe Macintosh browsers use "\x0d\x0a",
as that is the typical Apple (and Amiga) EOL sequence.

Anyway, the above RegExp won't work in Opera and IE, since "\x0d\x0a"
is two newline characters. The solution I can see, is to replace those
with a single newline first:

string.replace(/(\x0a\x0d|\x0d\x0a)/g,"\n");

Then test with the above RegExp.
Any help in this matter would be very much appreciated!


Hope this helps.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
DU
Sunil Kulkarni wrote:
I need to validate my TextArea as follows:

1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS
2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW

I need some kind of a JS validation for the same. I have tried using hard wrap
but that doesnt help completely.

Any help in this matter would be very much appreciated!
Thanks!
S Kulkarni


What's wrong with:

<form action="">
<p><textarea name="TextareaName" rows="5" cols="65"
wrap="soft"></textarea></p>
</form>

The string submitted can later be rendered within a textarea with the
same (or other) cols and rows attribute values.

On the wrap attribute, MSDN
http://msdn.microsoft.com/workshop/a...rties/wrap.asp
says:
soft: Default. Text is displayed with wordwrapping and submitted without
carriage returns and line feeds.
hard: Text is displayed with wordwrapping and submitted with soft
returns and line feeds.
off: Wordwrapping is disabled. The lines appear exactly as the user
types them.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #3
Thankyou very much for the suggestions!

Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<ll**********@hotpop.com>...
ku********@hotmail.com (Sunil Kulkarni) writes:
I need to validate my TextArea as follows:

1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS


I assume you mean rows :)
2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW

I need some kind of a JS validation for the same. I have tried using
hard wrap but that doesnt help completely.


A regular expression should be able to match zero to five lines of
zero to 65 characters, if you define the lines to be separated by
newlines ("\n").

If you want to look at automatic line wrapping, and count lines as
they are displayed, it gets ugly fast, but with some assumptions,
it should be manageable.

So, let's define a line to be up to 65 characters followed by a
newline characters, or just 65 characters followed by a newline, and
we want to check that a string contains at most 5 lines.

The final line can be up to 65 characters without being followed by a
newline.

A suitable regular expression is:
/^(.{0,65}\n|.{65}){0,4}.{0,65}\n?$/

However, the input of a textarea might not use a single character for
newlines. Both Opera and IE ends their lines with "\x0d\x0a"
(Carrige Return + newline, DOS EOL), where Mozilla uses "\x0a" (Just
newline, Typical Unix EOL). Maybe Macintosh browsers use "\x0d\x0a",
as that is the typical Apple (and Amiga) EOL sequence.

Anyway, the above RegExp won't work in Opera and IE, since "\x0d\x0a"
is two newline characters. The solution I can see, is to replace those
with a single newline first:

string.replace(/(\x0a\x0d|\x0d\x0a)/g,"\n");

Then test with the above RegExp.
Any help in this matter would be very much appreciated!


Hope this helps.
/L

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the...
4
by: ianv2 | last post by:
Hi I have the following form that I need advanced validation on, I would appreciate any help please. How can I validate the form so that the...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd...
5
by: Paul | last post by:
I normally use HTML_Quickform but new client's server doesn't have it and can't get it (ipowerweb.com). So I am reverting back to my beginnings and...
9
by: Andrew Poulos | last post by:
I'm dynamically populating a TEXTAREA with some info that includes a URL. Eg. frm.value = "This is the link to use <url: http://www.foo.com >"; ...
1
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and...
2
pradeepjain
by: pradeepjain | last post by:
Hii, I want to check for empty textarea with javascript ..say only blank space must also be treated as empty textarea...how to do it..is...
4
maxamis4
by: maxamis4 | last post by:
I currently have an input form in HTML. I am trying to use JavaScript to validate that the html forms are entered. I had it working earlier today but...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.