By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

Adding hyphens and underscore to my JS expression test

P: n/a
Hi All

Could somebody please confirm that if I change my JS expression test from:

if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z 0-9, but
nothing else.

It appears to work, but I don't know if I've screwed up the whole test
rather just the chars I want to add.

Rgds

Robbie
Dec 20 '05 #1
Share this Question
Share on Google+
38 Replies


P: n/a
On 20/12/2005 15:35, Astra wrote:

[snip]
if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z
0-9, but nothing else.


Yes, that is what should happen. However, why not avoid confusion by
placing the dash last in the character class ([...9_-])?

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 20 '05 #2

P: n/a
And lo, Astra didst speak in alt.www.webmaster,comp.lang.javascript:
Hi All

Could somebody please confirm that if I change my JS expression test
from:

if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z 0-9,
but nothing else.

It appears to work, but I don't know if I've screwed up the whole test
rather just the chars I want to add.


The hyphen character is *always* a special character within square
brackets in regular expressions. You'll need to escape it with a
backslash.

if (!(/^[a-zA-Z0-9\-_]*$/.test(document.form1.fred.value)))

It is important to note that outside of square brackets, the hyphen has
*no* special meaning and can be left unescaped.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 20 '05 #3

P: n/a
On 20/12/2005 15:58, GreyWyvern wrote:

[snip]
The hyphen character is *always* a special character within square
brackets in regular expressions.


Not at all. It's a special character when between a pair of characters
in which case it forms a range, but not in the OP's case (the 9 is
already part of a pair) and not at the very beginning or end of a class
(which is where I suggested it should go).

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 20 '05 #4

P: n/a
Many thanks guys.

Much appreciated.

Rgds Robbie

"Michael Winter" <m.******@blueyonder.co.uk> wrote in message
news:K3******************@text.news.blueyonder.co. uk...
On 20/12/2005 15:35, Astra wrote:

[snip]
if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z
0-9, but nothing else.


Yes, that is what should happen. However, why not avoid confusion by
placing the dash last in the character class ([...9_-])?

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 20 '05 #5

P: n/a

On Tue, 20 Dec 2005, GreyWyvern wrote:
And lo, Astra didst speak in alt.www.webmaster,comp.lang.javascript:
Hi All

Could somebody please confirm that if I change my JS expression test
from:

if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z 0-9,
but nothing else.

It appears to work, but I don't know if I've screwed up the whole test
rather just the chars I want to add.


The hyphen character is *always* a special character within square
brackets in regular expressions. You'll need to escape it with a
backslash.

if (!(/^[a-zA-Z0-9\-_]*$/.test(document.form1.fred.value)))

It is important to note that outside of square brackets, the hyphen has
*no* special meaning and can be left unescaped.


I thought that the hyphen is specified as a literal in a character range
by putting it first.

if (!(/^[-a-zA-Z0-9_]*$/.test(document.form1.fred.value)))
^^^^^^^^^^^^^
'-' or ( 'a' to 'z') or ( 'A' to 'Z') or ( '0' to '9') or '_'

'/' and '.' have to be escaped, though.

Quoting from one JavaScript reference of mine,

[snip]
: Using Special Characters to Verify Input
:
: In the following example, a user enters a phone number. When the user
: presses Enter, the script checks the validity of the number. If the number
: is valid (matches the character sequence specified by the regular
: expression), the script posts a window thanking the user and confirming
: the number. If the number is invalid, the script posts a window informing
: the user that the phone number is not valid.
:
: The regular expression looks for zero or one open parenthesis \(?,
: followed by three digits \d{3}, followed by zero or one close parenthesis
: \)?, followed by one dash, forward slash, or decimal point and when found,
: remember the character ([-\/\.]), followed by three digits \d{3}, followed
: by the remembered match of a dash, forward slash, or decimal point \1,
: followed by four digits \d{4}.
:
: The Change event activated when the user presses Enter sets the value of
: RegExp.input.
:
: <HTML>
: <SCRIPT LANGUAGE = "JavaScript1.2">
:
: re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
[snip]
The ECMA-262 standard says:

[pasting and reformatting from the PDF]

[snip]
: 15.10.2.16 NonemptyClassRangesNoDash
[snip]
: Informative comments: ClassRanges can expand into single ClassAtoms and/or
: ranges of two ClassAtoms separated by dashes. In the latter case the
: ClassRanges includes all characters between the first ClassAtom and the
: second ClassAtom, inclusive; an error occurs if either ClassAtom does not
: represent a single character (for example, if one is \w) or if the first
: ClassAtom's code point value is greater than the second ClassAtom's code
: point value. Even if the pattern ignores case, the case of the two ends of
: a range is significant in determining which characters belong to the
: range. Thus, for example, the pattern /[E-F]/i matches only the
: letters E, F, e,andf, while the pattern /[E-f]/i matches all upper and
: lower-case ASCII letters as well as the symbols [, \, ], ^, _,and`.
: A - character can be treated literally or it can denote a range. It is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^
: treated literally if it is the first or last character of ClassRanges, the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
: beginning or end limit of a range specification, or immediately follows a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
: range specification.
^^^^^^^^^^^^^^^^^^^^
[snip]

--
Norman De Forest http://www.chebucto.ns.ca/~af380/Profile.html
af***@chebucto.ns.ca [=||=] (At the Sign of the Flashing Cursor)
"Oh how I miss the days when it was easier to catch gonorhea than a
computer virus." -- Big Will in alt.comp.virus, March 9, 2005

Dec 20 '05 #6

P: n/a
Michael Winter wrote:
On 20/12/2005 15:35, Astra wrote:
if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z
0-9, but nothing else.


Yes, that is what should happen. However, why not avoid confusion by
placing the dash last in the character class ([...9_-])?


Why not /^[\w-]*$/?
F'up2 cljs

PointedEars
Dec 20 '05 #7

P: n/a
Norman L. DeForest wrote:
Quoting from one JavaScript reference of mine,

[...]
: <HTML>
: <SCRIPT LANGUAGE = "JavaScript1.2"> ^^^^^^^^[1] ^^^^^^^^^^^^^[2] :
: re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/; ^^[3] ^^[4] [snip]


At the latest here, you should burn your "Reference".

[1] That is not Valid HTML at all: <URL:http://validator.w3.org/>

You are correct in what you quoted from the ECMAScript specification.
However, ECMAScript 3 is not the relevant Edition for JavaScript 1.2,
that is ECMAScript 1, which did not define Regular Expressions before
Edition 3, that were JavaScript/JScript extensions at the time:

<URL:http://research.nihonsoft.org/javascript/jsref/corea3.htm#1158210>
<URL:http://msdn.microsoft.com/library/en-us/jscript7/html/jsobjregexpression.asp>

[2]
JavaScript 1.2 does not conform to ECMAScript 2 because when
the latter was still written, the former was already released:

<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:JavaScript_Overview#Rela tionship_between_JavaScript_and_ECMA_Versions>

With rare exceptions, you should never try to force the script engine
into JavaScript 1.2 compliant mode with "language='JavaScript1.2'".

[3] Undeclared global variable.
[4] The literal dot does not need to be escaped in ranges.
F'up2 cljs

PointedEars
Dec 20 '05 #8

P: n/a
And lo, Michael Winter didst speak in
alt.www.webmaster,comp.lang.javascript:
On 20/12/2005 15:58, GreyWyvern wrote:

[snip]
The hyphen character is *always* a special character within square
brackets in regular expressions.


Not at all. It's a special character when between a pair of characters
in which case it forms a range, but not in the OP's case (the 9 is
already part of a pair) and not at the very beginning or end of a class
(which is where I suggested it should go).


My apologies. I meant to say: one should *assume* the hyphen character is
always a special character within square brackets. Shortcuts like using
it as the first or last character within the brackets and not escaping it
are so easy to break down, especially if the regular expression is
dynamically created.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 20 '05 #9

P: n/a
On 20/12/2005 18:15, Thomas 'PointedEars' Lahn wrote:

[snip]
Why not /^[\w-]*$/?
:-D

Yes, that will do, too. Unless you're trying to avoid a bug ('feature'?)
in Mozilla which includes other characters from the Unicode repertoire.
F'up2 cljs


Last time I did that, someone in a.w.webmaster complained vehemently, so
I decided to avoid the hassle in my previous post.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 20 '05 #10

P: n/a
GreyWyvern wrote:
[...] Michael Winter [wrote]:
On 20/12/2005 15:58, GreyWyvern wrote:
The hyphen character is *always* a special character within square
brackets in regular expressions.


Not at all. It's a special character when between a pair of characters
in which case it forms a range, but not in the OP's case (the 9 is
already part of a pair) and not at the very beginning or end of a class
(which is where I suggested it should go).


My apologies. I meant to say: one should *assume* the hyphen character is
always a special character within square brackets.


But that is false. It becomes a special character under
special circumstances, which are those Michael mentioned.

Please stop crossposting over top-level hierarchies without
Followup-To.
F'up2 cljs

PointedEars
Dec 20 '05 #11

P: n/a
And lo, Thomas 'PointedEars' Lahn didst speak in comp.lang.javascript:
GreyWyvern wrote:
My apologies. I meant to say: one should *assume* the hyphen character
is always a special character within square brackets.
But that is false. It becomes a special character under
special circumstances, which are those Michael mentioned.


However, it *always* becomes a plain hyphen in square brackets when
escaped. Which is why I said it is good practice to assume that if it is
unescaped, it could be interpreted in a way which you don't expect.
Please stop crossposting over top-level hierarchies without
Followup-To.


Who are you? The deity of Usenet? This thread holds relevance to both
groups, and I believe individuals from both groups are taking part.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 20 '05 #12

P: n/a
Michael Winter wrote:
On 20/12/2005 18:15, Thomas 'PointedEars' Lahn wrote:
Why not /^[\w-]*$/?


:-D

Yes, that will do, too. Unless you're trying to avoid a bug ('feature'?)
in Mozilla which includes other characters from the Unicode repertoire.


The first character that is shown by

for (var i = 0x80; i < 0x110000; i++)
{
var c = String.fromCharCode(i)
if (/\w/.test(c))
{
alert("U+" + i.toString(16) + " = " + c);
break;
}
}

in

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051217
Debian/1.5.dfsg-2 Firefox/1.5 Mnenhy/0.7.3.0

[and Opera/8.51 (X11; Linux i686; U; en)]

is U+10030 which is displayed as "0" in the alert box for some reason,
and as

0 1 0
0 3 0

when written dynamically into an HTML document (probably because I do
not have the Unicode font for "LINEAR B SYLLABLE B012 SO" installed).

With

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20051007
Debian/1.7.12-1

the first character shown is U+00AA (ª -- "FEMININE ORDINAL INDICATOR").

It appears that this bug was fixed in Mozilla/5.0 release version 1.8
(JavaScript 1.6).
F'up2 cljs


Last time I did that, someone in a.w.webmaster complained vehemently,
so I decided to avoid the hassle in my previous post.


That is their problem. Crossposting over top-level hierarchies
is a Bad Thing, crossposting so without Followup-To is even worse.
PointedEars
Dec 20 '05 #13

P: n/a
GreyWyvern wrote
And lo, Thomas 'PointedEars' Lahn didst speak in comp.lang.javascript:
Please stop crossposting over top-level hierarchies without
Followup-To.


Who are you? The deity of Usenet?


Tee hee! He does have a snazzy X-Face though!

--
Charles Sweeney
http://CharlesSweeney.com
Dec 20 '05 #14

P: n/a

On Tue, 20 Dec 2005, Thomas 'PointedEars' Lahn wrote:
Norman L. DeForest wrote:
Quoting from one JavaScript reference of mine,

[...]
: <HTML>
: <SCRIPT LANGUAGE = "JavaScript1.2"> ^^^^^^^^[1] ^^^^^^^^^^^^^[2]
:
: re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;

^^[3] ^^[4]
[snip]


At the latest here, you should burn your "Reference".


I don't think my hard drive would burn very well. :)

[1] That is not Valid HTML at all: <URL:http://validator.w3.org/>
It was a direct cut-and-paste from the reference. I wasn't trying
to single out any specific version of JavaScript, just including the
context of the quote.

You are correct in what you quoted from the ECMAScript specification.
However, ECMAScript 3 is not the relevant Edition for JavaScript 1.2,
that is ECMAScript 1, which did not define Regular Expressions before
Edition 3, that were JavaScript/JScript extensions at the time:

<URL:http://research.nihonsoft.org/javascript/jsref/corea3.htm#1158210>
<URL:http://msdn.microsoft.com/library/en-us/jscript7/html/jsobjregexpression.asp>

[2]
JavaScript 1.2 does not conform to ECMAScript 2 because when
the latter was still written, the former was already released:

<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:JavaScript_Overview#Rela tionship_between_JavaScript_and_ECMA_Versions>
Ahhh! *This* is what I have been looking for. My original JavaScript
references were downloaded from the server at developer.netscape.com and I
have been unable to connect to that system for some time to look for any
available later references. It appears as though the documentation has
been moved to the Mozilla site. I'll have to look there. Thank you very
much.

With rare exceptions, you should never try to force the script engine
into JavaScript 1.2 compliant mode with "language='JavaScript1.2'".


I was directly quoting the reference to show context, not singling out
JavaScript 1.2. In fact, I was so interested in getting the text related
to the '-' in ranges that I never noticed the "1.2" at all. (The
reference the quoted text comes from, downloaded from Netscape's site, was
for JavaScript 1.5. Another look shows that a lot of their examples have
the "JavaScript1.2" language specification in the SCRIPT tag.) In none of
my pages that use JavaScript have I specified any version number
whatsoever.

--
Norman De Forest http://www.chebucto.ns.ca/~af380/Profile.html
af***@chebucto.ns.ca [=||=] (At the Sign of the Flashing Cursor)
"Oh how I miss the days when it was easier to catch gonorhea than a
computer virus." -- Big Will in alt.comp.virus, March 9, 2005

Dec 20 '05 #15

P: n/a
Norman L. DeForest wrote:
On Tue, 20 Dec 2005, Thomas 'PointedEars' Lahn wrote:
Norman L. DeForest wrote:
> Quoting from one JavaScript reference of mine,
>
> [...]
> : <HTML>
> : <SCRIPT LANGUAGE = "JavaScript1.2"> ^^^^^^^^[1] ^^^^^^^^^^^^^[2]
> :
> : re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;

^^[3] ^^[4]
> [snip]


At the latest here, you should burn your "Reference".


I don't think my hard drive would burn very well. :)


Replacing the files will do fine :)
[1] That is not Valid HTML at all: <URL:http://validator.w3.org/>


It was a direct cut-and-paste from the reference.


Which is exactly my point. The "reference" is badly outdated, and even
then it was not fitted to the task. Script code operating within and
on invalid markup is even less reliable than it is as-is.
[...]
<URL:http://research.nihonsoft.org/javascript/jsref/corea3.htm#1158210>
<URL:http://msdn.microsoft.com/library/en-us/jscript7/html/jsobjregexpression.asp> [...]
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:JavaScript_Overview#Rela tionship_between_JavaScript_and_ECMA_Versions>
Ahhh! *This* is what I have been looking for. My original JavaScript
references were downloaded from the server at developer.netscape.com and I
have been unable to connect to that system for some time to look for any
available later references.
Yet mirrors exist, Google would have been your friend again :)
It appears as though the documentation has been moved to the Mozilla site.
I'll have to look there. Thank you very much.


You're welcome :)

Wikipedia (<URL:http://en.wikipedia.org/wiki/JavaScript>) also had some
links to authoring guides and reference material already, which I updated
this morning.

You may also want to visit
<URL:http://PointedEars.de/scripts/js-version-info> once in a while.
With rare exceptions, you should never try to force the script engine
into JavaScript 1.2 compliant mode with "language='JavaScript1.2'".


[...] In none of my pages that use JavaScript have I specified any
version number whatsoever.


Good man :)
Regards,
PointedEars
Dec 20 '05 #16

P: n/a
GreyWyvern wrote:
And lo, Thomas 'PointedEars' Lahn didst speak in comp.lang.javascript:
GreyWyvern wrote:
My apologies. I meant to say: one should *assume* the hyphen character
is always a special character within square brackets.
But that is false. It becomes a special character under
special circumstances, which are those Michael mentioned.


However, it *always* becomes a plain hyphen in square brackets when
escaped.


Yes, but that is not what you stated.
Which is why I said it is good practice to assume that if it is
unescaped, it could be interpreted in a way which you don't expect.
Good practice is defined by the overall knowledge of participants,
and coders should have a minimum clue about coding. It is clearly
defined where an unescaped hyphen becomes special and where not.
Please stop crossposting over top-level hierarchies without
Followup-To.


Who are you? The deity of Usenet?


Who are you, ignoring Netiquette?
This thread holds relevance to both groups, and I believe individuals
from both groups are taking part.


That is no valid argument. Crossposting over top-level hierarchies, and
into the Big Eight from the outside is evil[tm] in the first place. With
the, let's say, "loose" structure of alt.ALL, anything becomes possible
regarding this. If alt.ALL were properly organized, a group like
alt.www.webmaster would not even exist because there already is
comp.infosystems.www.authoring.ALL.
PointedEars
Dec 20 '05 #17

P: n/a
Writing in news:comp.lang.javascript
From the safety of the PointedEars Software (PES) cafeteria
Thomas 'PointedEars' Lahn <Po*********@web.de> said:
GreyWyvern wrote:

Who are you? The deity of Usenet?


Who are you, ignoring Netiquette?


Now then children, play nice.
...
If alt.ALL were properly organized, a group like
alt.www.webmaster would not even exist because there already is
comp.infosystems.www.authoring.ALL.


An interesting idea, however groups in the ciwa sub-hierarchy are fairly
narrow in focus - that's not a criticism, it's just the way it is. Those
that prefer that type of structure will eventually find their way over
there.

--
William Tasso

Save the drama
for your Mama.
Dec 20 '05 #18

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/20/2005 3:41 PM:

<snip>
Wikipedia (<URL:http://en.wikipedia.org/wiki/JavaScript>) also had some
links to authoring guides and reference material already, which I updated
this morning.


If you are updating Wikipedia then it is even more evidence that it
lacks credibility and you need more/better resources/references.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '05 #19

P: n/a
On Tue, 20 Dec 2005 20:48:55 +0100, Thomas 'PointedEars' Lahn
<Po*********@web.de> posted something that included:
Please stop crossposting over top-level hierarchies without
Followup-To.

Who are you? The deity of Usenet?

Who are you, ignoring Netiquette?


Netiquette is not a matter of opinion; the Internet Engineering Task
Force published RFC 1855 over a decade ago.

According to Netiquette, you SHOULD crosspost an article of interest
to more than one newsgroup, and you SHOULD NOT set followups without
warning participants, who have a reasonable right to expect that they
will see responses to what they say.

There ain't NOTHING in Netiquette to prohibit or even to discourage
crossposting across top-level heirarchies.

If you want to make up your own rules of conduct, you are perfectly
welcome to engineer an alternative to the internet, and publish your
own version of Net News on it.


--
If we're losing 40-130 species a day,
How come nobody can itemize them?
And why can't fruitflies be one of them?
Dec 20 '05 #20

P: n/a
JRS: In article <op***************@greywyvern.belkin>, dated Tue, 20
Dec 2005 14:11:52 local, seen in news:comp.lang.javascript, GreyWyvern
<sp**@greywyvern.com> posted :
Please stop crossposting over top-level hierarchies without
Followup-To.


Who are you? The deity of Usenet? This thread holds relevance to both
groups, and I believe individuals from both groups are taking part.


He is a reincarnation of Mussolini, with ideas above his station.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Dec 20 '05 #21

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 12/20/2005 3:41 PM:
Wikipedia (<URL:http://en.wikipedia.org/wiki/JavaScript>) also had
some links to authoring guides and reference material already, which
I updated this morning.


If you are updating Wikipedia then it is even more evidence that it
lacks credibility and you need more/better resources/references.


<URL:http://www.nature.com/news/2005/051212/full/438900a.html>

But it is not possible to satisfy a born ignorant like you.
PointedEars
Dec 21 '05 #22

P: n/a
And lo, Thomas 'PointedEars' Lahn didst speak in comp.lang.javascript:
GreyWyvern wrote:
However, it *always* becomes a plain hyphen in square brackets when
escaped.


Yes, but that is not what you stated.


For the benefit of those who don't have a good grasp of regular
expressions (which is a *lot* of people) it is good to reinforce good
composition technique. Despite exceptions and shortcuts, one of these
techniques is to ensure plain hyphens are escaped within square brackets;
this way one can always be sure of their function.

The methods you espouse are merely syntactic sugar.
Which is why I said it is good practice to assume that if it is
unescaped, it could be interpreted in a way which you don't expect.


Good practice is defined by the overall knowledge of participants,
and coders should have a minimum clue about coding. It is clearly
defined where an unescaped hyphen becomes special and where not.


Oh? And you would take the time to describe all these exceptions and
definitions to someone who's having trouble with regular expressions?

I'll admit, the way I originally phrased my answer was false, however, I
cheerfully corrected myself. Thank you for pointing it out.
Please stop crossposting over top-level hierarchies without
Followup-To.


Who are you? The deity of Usenet?


Who are you, ignoring Netiquette?


It is awfully rude to keep setting the F'up-to to a group which is not
read by the individuals you are debating with.
This thread holds relevance to both groups, and I believe individuals
from both groups are taking part.


That is no valid argument. Crossposting over top-level hierarchies, and
into the Big Eight from the outside is evil[tm] in the first place.


Who says? You and your holier-than-thou secret comp-heirarchy society?
Most folks who live in the comp groups are nice regular people who are
happy to help out in the alt groups but prefer a narrower focus. I
sincerely hope you don't think you represent them. I should think they
would be insulted.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 21 '05 #23

P: n/a
And lo, Thomas 'PointedEars' Lahn didst speak in alt.www.webmaster:
William Tasso wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> said:
If alt.ALL were properly organized, a group like
alt.www.webmaster would not even exist because there
already is comp.infosystems.www.authoring.ALL.


An interesting idea, however groups in the ciwa sub-hierarchy are fairly
narrow in focus - that's not a criticism, it's just the way it is.


You could not be more wrong.


I don't think you understand what William means by "narrow in focus".
Those that prefer that type of structure will eventually find their way
over there.


The last time I checked on my news server (about a minute ago), there are

[snip: bunchacompgroups]


All of which are *individually* much more narrow in focus than the groups
under alt.www. Like William says, this is not criticism nor is it an
insult of any kind, it is the way things are. Often a narrower focus is
just what one is looking for; for others, it is sufficient to know a
little about many topics.

If this offends you somehow... well, let's just say you need to relax.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 21 '05 #24

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/20/2005 7:32 PM:
Randy Webb wrote:

Thomas 'PointedEars' Lahn said the following on 12/20/2005 3:41 PM:
Wikipedia (<URL:http://en.wikipedia.org/wiki/JavaScript>) also had
some links to authoring guides and reference material already, which
I updated this morning.


If you are updating Wikipedia then it is even more evidence that it
lacks credibility and you need more/better resources/references.

<URL:http://www.nature.com/news/2005/051212/full/438900a.html>

But it is not possible to satisfy a born ignorant like you.


I have told you already, repeatedly, that if you do not understand the
language and it's dialects then you shouldn't endeavor in trying to
understand anything written in it.

But for the sake of posterity, let me explain what I said in a way that
you may understand it:

A reference (in this case Wikopedia) is only as good as its contributors.
Considering that all you have to do to be a contributor to Wikipedia is
to have an Internet Connection, the ability to click the "Edit this
Page" link at the top, Edit it and Save it, then the realm of
contributors is practically unlimited.

I edited the Javascript section you provided the URL to while typing
this response. If I don't forget, I will change it back tomorrow. Or,
can you tell me what I changed?

The sheer coverage of contributors and that the paragraph on Whitespace
has several inaccuracies and mis-leading conclusions, then the
indication has to be that it's not a very resource when it comes to
JavaScript and JScript.
If you took that personal then you have a problem.

Now, if you want to continue this in an educated civilized manner, fine.
If you want to make it personal, that is fine also.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Dec 21 '05 #25

P: n/a
["Followup-To:" header set to comp.lang.javascript.]
On 2005-12-20, GreyWyvern <sp**@greywyvern.com> wrote:
And lo, Astra didst speak in alt.www.webmaster,comp.lang.javascript:
Hi All

Could somebody please confirm that if I change my JS expression test
from:

if (!(/^[a-zA-Z0-9]*$/.test(document.form1.fred.value)))

to

if (!(/^[a-zA-Z0-9-_]*$/.test(document.form1.fred.value)))

(in other words I've added the hyphen and underscore after the 9)

then I'm allowing the hyphen and underscore as valid chars like a-z 0-9,
but nothing else.

It appears to work, but I don't know if I've screwed up the whole test
rather just the chars I want to add.
The hyphen character is *always* a special character within square
brackets in regular expressions.

You'll need to escape it with a
backslash.

if (!(/^[a-zA-Z0-9\-_]*$/.test(document.form1.fred.value))) ???

is this unique to javascript regular expressions.

in ordinary (posix 1003.2) REs
- is non special at either end of a brasked expression and
\ is always literal inside brackets.
It is important to note that outside of square brackets, the hyphen has
*no* special meaning and can be left unescaped.


it seems that in javascript RE bracket expression - is literal at the
end of the expression or if escaped and \ must be doubled to be literal.
Bye.
Jasen
Dec 21 '05 #26

P: n/a
Randy Webb <Hi************@aol.com> writes:
I edited the Javascript section you provided the URL to while typing
this response. If I don't forget, I will change it back tomorrow. Or,
can you tell me what I changed?


That's easy! You made "object-based" on line 1 no longer be a Wiki-link.

I could change it back, but I'll let you do it.

/L 'compare NNTP-posting-host to history :P'
--
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.'
Dec 21 '05 #27

P: n/a
And lo, Jasen Betts didst speak in comp.lang.javascript:
On 2005-12-20, GreyWyvern <sp**@greywyvern.com> wrote:
You'll need to escape it with a
backslash.

if (!(/^[a-zA-Z0-9\-_]*$/.test(document.form1.fred.value)))

???

is this unique to javascript regular expressions.

in ordinary (posix 1003.2) REs
- is non special at either end of a brasked expression and
\ is always literal inside brackets.


Javascript uses Perl compatible regular expressions.
It is important to note that outside of square brackets, the hyphen has
*no* special meaning and can be left unescaped.


it seems that in javascript RE bracket expression - is literal at the
end of the expression or if escaped and \ must be doubled to be literal.


Exactly :) However, since a plain - can be special OR literal within
square brackets depending on where it is placed, it is good form always to
escape it. This way you are *sure* it is being taken as a literal, and is
a big help for those who may edit your expressions later, or if you build
your expressions dynamically.

Please stop setting the followup; it is quite rude. Interested parties
from both x-posted groups are participating in this thread.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search - PHP/MySQL site
search engine
Dec 21 '05 #28

P: n/a
VK
<offtopic>
Lasse Reichstein Nielsen wrote:
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>


FYI:
Death colors do not work on FF 1.5 Final - just an empty black canvas
is displayed.
It still works on the latest Opera 8.51

</offtopic>

Dec 21 '05 #29

P: n/a
VK

VK wrote:
<offtopic>
Lasse Reichstein Nielsen wrote:
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>


FYI:
Death colors do not work on FF 1.5 Final - just an empty black canvas
is displayed.
It still works on the latest Opera 8.51

</offtopic>


It works again. What was the trick?

Dec 21 '05 #30

P: n/a
On Tue, 20 Dec 2005 22:29:13 -0500, GreyWyvern <sp**@greywyvern.com>
posted something that included:
For the benefit of those who don't have a good grasp of regular
expressions (which is a *lot* of people) it is good to reinforce good
composition technique.


The many people who don't have a good grasp includes those who write
the parsers. There are at least seven major flavors of regular
expressions.

Anyone who claims a good grasp ought to be held for 72 hours to
determine whether he presents a threat to the safety of himself and
others.
--
If we're losing 40-130 species a day,
How come nobody can itemize them?
And why can't fruitflies be one of them?
Dec 21 '05 #31

P: n/a
Lasse Reichstein Nielsen said the following on 12/21/2005 7:46 AM:
Randy Webb <Hi************@aol.com> writes:

I edited the Javascript section you provided the URL to while typing
this response. If I don't forget, I will change it back tomorrow. Or,
can you tell me what I changed?

That's easy! You made "object-based" on line 1 no longer be a Wiki-link.

I could change it back, but I'll let you do it.


Fixed it. It only goes to prove my point that anybody can change it so
it makes what you read there questionable.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '05 #32

P: n/a
["Followup-To:" header set to comp.lang.javascript.]

For the benefit of those who don't have a good grasp of regular
expressions (which is a *lot* of people) it is good to reinforce good
composition technique.
it seems javascript regular expressions subtly unlike other regular
expressions, this may account for some of the misunderstanding.
Despite exceptions and shortcuts, one of these
techniques is to ensure plain hyphens are escaped within square brackets;
this way one can always be sure of their function.


using the backslash in that way will reinforce the differences
between javascript's and other REs.

Bye.
Jasen
Dec 21 '05 #33

P: n/a
And lo, Jasen Betts didst speak in comp.lang.javascript:
["Followup-To:" header set to comp.lang.javascript.]
["Followup-To:" header unset]
For the benefit of those who don't have a good grasp of regular
expressions (which is a *lot* of people) it is good to reinforce good
composition technique.


it seems javascript regular expressions subtly unlike other regular
expressions, this may account for some of the misunderstanding.


They behave this way in all Perl-Compatible implementations that I'm
familiar with. I don't see from where your misunderstanding arises.

Which PCRE implementations are you using which differ?
using the backslash in that way will reinforce the differences
between javascript's and other REs.


This is a Good Thing(TM). It is important to know what type of regexps
you are limited to before composing any expression.

Grey

--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#sear - Orca Search: Full-featured spider
and site-search engine
Dec 21 '05 #34

P: n/a
"VK" <sc**********@yahoo.com> writes:
It works again. What was the trick?


You tell me, I read both your messages at the same time :)
/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.'
Dec 22 '05 #35

P: n/a
VK

Lasse Reichstein Nielsen wrote:
"VK" <sc**********@yahoo.com> writes:
It works again. What was the trick?


You tell me, I read both your messages at the same time :)
/L


Really weird... I'm sure that was just a black canvas - and next time
it worked. Must be a glitch on my side, or a temporary bandwidth jam.
Sorry for troubles.

Dec 22 '05 #36

P: n/a
Paul Ding wrote:
[...] GreyWyvern <sp**@greywyvern.com> posted [...]:
For the benefit of those who don't have a good grasp of regular
expressions (which is a *lot* of people) it is good to reinforce good
composition technique.


The many people who don't have a good grasp includes those who write
the parsers. There are at least seven major flavors of regular
expressions.


Care to elaborate?
PointedEars
Dec 22 '05 #37

P: n/a
Lasse Reichstein Nielsen wrote:
Randy Webb <Hi************@aol.com> writes:
I edited the Javascript section you provided the URL to while typing
this response. If I don't forget, I will change it back tomorrow. Or,
can you tell me what I changed?
That's easy! You made "object-based" on line 1 no longer be a Wiki-link.

I could change it back, but I'll let you do it.


Yeah, let the AOHell kid have its fun, let it destroy what it is
incapable to understand. If all is going well, such attempts at
destructive wiki-ing, in sharp constrast to my constructive ones,
will not be successful any longer soon. de.wikipedia.org already
introduced registering before editing, I am pretty sure
en.wikipedia.org will follow. Accounts of people who use their
account to destroy Wikipedia will be removed, and the version
control makes it easy to restore what they attempted to destroy.
/L 'compare NNTP-posting-host to history :P'


Do not expect a kid at this level of the learning curve to understand the
Net.
PointedEars
Dec 22 '05 #38

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/22/2005 9:13 AM:
Lasse Reichstein Nielsen wrote:

Randy Webb <Hi************@aol.com> writes:
I edited the Javascript section you provided the URL to while typing
this response. If I don't forget, I will change it back tomorrow. Or,
can you tell me what I changed?
That's easy! You made "object-based" on line 1 no longer be a Wiki-link.

I could change it back, but I'll let you do it.

Yeah, let the AOHell kid have its fun, let it destroy what it is
incapable to understand.


Your self pronounced stupidity never ceases to amaze me.

If all is going well, such attempts at destructive wiki-ing, in sharp
constrast to my constructive ones, will not be successful any longer soon.
I have told you many many times, and I guess I will tell you again.
Before you attempt to use a language (in this case English), you should
endeavor to understand what you are saying. You don't.

There was no "attempt at destructive wiki-ing". It was to prove a point,
which you missed.
de.wikipedia.org already introduced registering before editing,
I am pretty sure en.wikipedia.org will follow.
It will.
Accounts of people who use their account to destroy Wikipedia will
be removed, and the version control makes it easy to restore what
they attempted to destroy.


Once again, you couldn't be further from the issue. The purpose of
registering had nothing to do with "destroying" Wiki. It has to do with
being able to track who posts what. It came about from an article that
was posted that had harmful personal information (incorrect information)
in it. Wiki decided to implement the registration process afterwards.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 23 '05 #39

This discussion thread is closed

Replies have been disabled for this discussion.