在我的JS表达式测试中添加连字符和下划线 [英] Adding hyphens and underscore to my JS expression test

查看:69
本文介绍了在我的JS表达式测试中添加连字符和下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


有人可以确认一下,如果我改变我的JS表达式测试:


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





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


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


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

没有别的。


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

而不仅仅是字符我想补充一下。


Rgds


罗比

解决方案

< blockquote> /.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]*


这篇关于在我的JS表达式测试中添加连字符和下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆