473,772 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding hyphens and underscore to my JS expression test

Hi All

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

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

to

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

(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
38 4542
JRS: In article <op************ ***@greywyvern. belkin>, dated Tue, 20
Dec 2005 14:11:52 local, seen in news:comp.lang. javascript, GreyWyvern
<sp**@greywyver n.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.demo n.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
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 12/20/2005 3:41 PM:
Wikipedia (<URL:http://en.wikipedia.or g/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
And lo, Thomas 'PointedEars' Lahn didst speak in comp.lang.javas cript:
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
And lo, Thomas 'PointedEars' Lahn didst speak in alt.www.webmaster:
William Tasso wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> said:
If alt.ALL were properly organized, a group like
alt.www.webmaster would not even exist because there
already is comp.infosystem s.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: bunchacompgroup s]


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
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.or g/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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Dec 21 '05 #25
["Followup-To:" header set to comp.lang.javas cript.]
On 2005-12-20, GreyWyvern <sp**@greywyver n.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.valu e)))

to

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

(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.valu e))) ???

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
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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Dec 21 '05 #27
And lo, Jasen Betts didst speak in comp.lang.javas cript:
On 2005-12-20, GreyWyvern <sp**@greywyver n.com> wrote:
You'll need to escape it with a
backslash.

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

???

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
VK
<offtopic>
Lasse Reichstein Nielsen wrote:
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.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
VK

VK wrote:
<offtopic>
Lasse Reichstein Nielsen wrote:
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.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

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

Similar topics

1
1516
by: Michelle | last post by:
I have been trying to work out a regular expression to test for ONLY numbers, no hyphens so that I can accept only hyphen-less phone numbers...I have had no luck Any ideas out there... TIA, Miki
5
4974
by: richard_thomas | last post by:
Hi, I'm having trouble running the following query: select * from message where text_body like ' ----------%' ie, five spaces followed by at least ten hyphens. The query doesn't complete, so eventually I cancel it. If I remove the hyphens from the query ("... like ' %'") then it runs fine (though it doesn't find the correct data).
18
20529
by: Gustaf Liljegren | last post by:
IE does, and I can't remember this used to be a problem in Netscape. I guess someone in the Mozilla team just came up with a Smart Idea about the True Semantics of the Hyphen Minus character. :-( How do I make IE and Firefox agree to make hyphens trigger a linebreak? Gustaf
2
6057
by: Herbert Liechti | last post by:
Hello I like to grant some permissions to the user www-data (default user for apache under debian) GRANT SELECT, UPDATE, INSERT, DELETE ON customer TO herbie, www-data; The statements throws the following error: ERROR: parser: parse error at or near "-" at character 64
46
2741
by: James Harris | last post by:
Before I embark on a new long-term project I'd appreciate your advice on how to split up long names. I would like to keep the standards for command names the same as that for variable names. Looking at the examples below, which ones seem better? Straight names echoclient lastcharoffset helloworld Internal underscores
1
10195
by: Guadala Harry | last post by:
The following function, SplitTheString(), splits a string based on a flag that is like this: {Flag1:whateverHere} Note that the "whateverHere" part can be any character - and at least one character. I simply want to extend this RegEx to do the same job - but to do it based on an additional possible flag: {Flag2:whateverHere}
5
2313
by: ibiza | last post by:
Hi all, I have a question which I have no ideal of the answer...I am currently working on a web application and at some time, I have a string representing a short text. This could be a simple example : "This is my list :\n\r-list item 1\n\r-list item 2\n\r-list item 3\n\r\n\rThis was a great list." Let's say this outputs like that :
16
3386
by: Jim Langston | last post by:
I know that functions starting with an underscore, or two underscores, are reserved by the compiler/c++ and should not be used by the user and may cause undefined behavior. My question is, how likely is it to actually cause undefined behavior? The reason I'm asking is I'm using a game engine where the sockets code is not working correctly on my computer, but seems to work correctly on everyone elses. I am not compiling the dll myself,...
4
4107
by: almurph | last post by:
Hi, Wondering if you can help me here. Given a string length "m" how do you insert 3 hyphens in differing positions such that the following conditions are met: a. all positions are covered b. no pattern is repeated.
0
9454
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
10264
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
10106
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...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
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...
0
6716
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
5355
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
4009
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
3610
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.