473,856 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 32429
ku********@hotm ail.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|.{6 5}){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="TextareaN ame" 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********@hotm ail.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|.{6 5}){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
2616
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 validation on both. Is there a way to link the drop-down choice to the correspondent validation section while disabling validation for the other one? here's what I presently have:
4
1556
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 and if they choose 'other' the focus goes to the 'otherfeedback' textarea which also has to have a value. <form action="feedback.cfm" method="post" name="form" id="Form"
27
4782
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
11
3004
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
5
1413
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. If you know of any links to classes or files (yes, I have already searched google) that you like and are EASY to use/implement, please post them or links to them. Many thanks!
9
2405
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 validate. I tried escaping the value but then I get entities displaying in the TEXTAREA. Is there a way to change the value without upsetting the page's validation?
1
1969
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 has server side validation in but i want to add some client side javascript validation. How can do i this when there is alreay a "returnvalidate comment()" in? The only two fields i want to validate are "subject" and "comment" since the rest are drawn...
2
1670
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
2157
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 a look and tell me why its not working. php html page <?php require_once('auth.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
0
9766
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11066
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10702
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9536
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7935
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7099
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4584
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4177
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.