English 中文(简体)
这一次工作如何?
原标题:How does this time Regex Work?

我刚刚继承了一个预测,客户方面有许多验证。

我发现,这名检查员没有见到评论。 我承认reg无疑是我的失败点之一。 (In Javascript!)

var myRegxp = /(([0]*[1-9]{1})|([1]{1}[0-2]{1}))(/{1})((19[0-9]{2})|([2-9]{1}[0-9]{3}))$/;
if (!myRegxp.test(args.Value))
{//do fail stuff here};

从该网页的其余部分看,我确信,它本应检查某种日期格式。 这是否通过MM/YYYYY。 从一些早期测试开始,它就做到了attle

如果这种reg子与MM/YYYYY相吻合,那么这样做的最佳方式是什么?

督促会长提出任何建议。

最佳回答

它应当与MMM/YYYYYYYYYYY(MMM为1-12,YYYY为190-99)结束。

(月数)

([0]*[1-9]{1})
zero or more occurences of  0 , and one occurence of 1-9
Example match: 01

页: 1

([1]{1}[0-2]{1})
1 match of  1 , 1 match of 0-2
Example match: 10

第二期会议(年),首先与以下几方面相呼应:

(/{1})

接着是:

((19[0-9]{2})
One match of  / , 19 and two matches of 0-9 (looks like a year in the range 1900-1999)
Example match: 1900

页: 1

([2-9]{1}[0-9]{3})
1 match of 2-9 and thee matches of 0-9 (looks like a year in the range 2000-9999
Example match: 2000

简明:

var myRegExp = /^(0[1-9]|1[0-2])/(19d{2}|[2-9]d{3})$/;

注:<代码>d为0-9的特性类别。 I ve除去了用于分类的括号,因为它们没有用于myRegExp.test。 <>Replaced [0]* by 0?,因为它不应与0000001/2010相匹配,而是应当与1/2010<>匹配。 替换<代码>[0]∗,0 因为它应当字面上匹配<代码>01,而不是1。 在删除这些内容时,这一保留将与包含MM/YYYYYY的任何案文一致。

问题回答

我同意——它正在以MM/yyyyyy的形式核对日期。

它允许本月的任何领导零。 它允许使用19条<代码>xx或从<代码>2和<代码>9之间的数字开始的任何东西。 也就是说,它允许在以下年份达到99999年:





相关问题
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.

热门标签