English 中文(简体)
Javascript RegEx Not Working [duplicate]
原标题:Javascript RegEx Not Working [duplicate]

I have the following javascript code:

    function checkLegalYear() {
        var val = "02/2010"; 

        if (val !=   ) {
           var regEx = new RegExp("^(0[1-9]|1[0-2])/d{4}$", "g");

            if (regEx.test(val)) {
               //do something
            }
            else {
               //do something
            }
        }
    }

然而,我的格言 试卷总是以任何价值(02/2010年)为回报。 我的法典中是否有错误? 我在网上对这部法律进行了审判,并做了罚款。

最佳回答

由于你重新从扼杀中经常表达,你必须把你的反感增加一倍:

var regEx = new RegExp("^(0[1-9]|1[0-2])/\d{4}$", "g");

当你开始扼杀时,你必须说明,经常表达首先会被贬低,即, Java语不断。 显示恒定的辛金对定期表达方式没有任何了解,而且它自己也用于反弹。 因此,到主讲时,在座标语时,会看一看你的源码时,会发现许多不同之处。 你们的消息来源像

"^(0[1-9]|1[0-2])/d{4}$"

but after the string parse it s

^(0[1-9]|1[0-2])/d{4}$

请注意,<代码>d现为d

By doubling the backslash characters, you re telling the string parser that you want single actual backslashes in the string value.

这里确实没有任何理由不使用经常表达的同义词:

var regEx = /^(0[1-9]|1[0-2])/d{4}$/g;

<>edit——我还注意到,如果你使用regex syntax,就必须引用含有的“/”特性。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签