473,394 Members | 1,935 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,394 software developers and data experts.

newline character in string constant

Hi!

I have a form with a textarea field. I want to validate the input from
the textarea using javascript. Suppose I want to check that the user
has not entered the string:
"Hello
World!"

To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"

So how do I do my check?

Regards,
Shobhit

Jul 23 '05 #1
3 7924
sh************@gmail.com writes:
To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"


No it doesn't, unless you are doing something more that you haven't
shown us. So, give a link to the page where it fails (preferably
a small, self-contained page showing only the problem).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
sh************@gmail.com wrote:
Hi!

I have a form with a textarea field. I want to validate the input from
the textarea using javascript. Suppose I want to check that the user
has not entered the string:
"Hello
World!"

To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"

So how do I do my check?

Regards,
Shobhit


This doesn't happen in pure JavaScript.

I'm going to take a wild guess that this line of code is being output
by PHP, PERL, or some similar server-side tongue. In this case, it is
the server-side language that is interpolating the \n.

If this is the case, depending on the language and the way you're
outputing it, you may be able to double-escape it to \\n.

Jul 23 '05 #3
I am using perl to output the script. Now I am double-escaping it using
\\n. Though the script is output correctly i.e form["text"].value ==
"Hello\nWorld" but when the check still fails.

Shobhit

Jul 23 '05 #4

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

Similar topics

6
by: 3strands | last post by:
Hi! I am writing a C++ program for a school project. It's a project and I could do it without this particualr feature, it's just it would be better if I could find out one thing: I'm making...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
2
by: Jim Heavey | last post by:
If I have a "long" string variable which is a I break up into a multiline value, I get a "Newline Constant" error in the compiler. If I make it all a single line, then it has no problem. In VB,...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
5
by: Adam Right | last post by:
Hi, Is there a way to construct the mail body including newline characters by using .net framework mailing functions when sending an email? I cannot insert newline character into the body of the...
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
11
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const...
18
by: Andrew Backer | last post by:
Is it possible to embed a newline constant in a string in the same way as c#? I really don't want to do something like this: ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.