且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在我的JS表达式测试中添加连字符和下划线

更新时间:2023-02-19 12:18:21

/.test(document.form1.fred.value)))





if(!(/ ^ [a- zA-Z0-9 -_] *


/ .test(document.form1.fred.value)))


(换句话说)我在9)之后添加了连字符和下划线。


然后我允许连字符和下划线作为有效字符,如az 0-9,但

没有别的。


它似乎有用,但我不知道我是否搞砸了整个测试

而不仅仅是我要添加的字符。


Rgds


Robbie


2005年12月20日15:35,Astra写道:


[snip]
if(!(/ ^ [a-zA-Z0-9] *


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

/.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


On 20/12/2005 15:35, Astra wrote:

[snip]
if (!(/^[a-zA-Z0-9]*