473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 32367
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 contact choice. Right now it is set to enforce...
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 user has to select an option from the select box...
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 Javascript form validation functions, but it...
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 like to add a lot of possibilities to check wether...
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 have forgotten how to validate forms easily. ...
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 >"; but this results in a page that doesn't...
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 the comments open up in a new window. It already...
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 there any script for this .
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 now my form is not validating. Could someone take...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.