JavaScript RegularExpression asp.net mvc

时间:2013-06-27 13:41:57

标签: javascript jquery asp.net-mvc regex javascript-events

你好,我在 asp.net mvc 2中的RegularExpression中新增了整天都在寻找合适的语法试验和错误。

如果有人能帮助你那么多。

问题在于:

最少工作时数/天 - >允许的浮点数但不大于24

最少工时/周 - >允许的浮点数但不大于56

我试图创建正则表达式,如果输入是整数或浮点数但不大于24,则接受该正则表达式。

此外,如果输入有空白区域,则打印ErrorMessage =“不允许空格”


查看

<td>
<%= Html.TextBoxFor(model => model.dblMinHrs, new { @class = "txtInput"})%>
<%= Html.ValidationMessageFor(model => model.dblMinHrs)%>
</td>

<td>
<%= Html.TextBoxFor(model => model.dblMinWk, new { @class = "txtInput"})%>
<%= Html.ValidationMessageFor(model => model.dblMinWk)%>
</td>

MODEL

[RegularExpression("([0-1]\\d{0,1})|(2[0-4])", ErrorMessage = "Must not greater than 24")]
  public double dblMinHrs { get; set; }


  [RegularExpression("([0-4]\d{0,1})|(5[0-6])", ErrorMessage = "Must not greater than 24")]
  public double dblMinWk { get; set; }

任何人都请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:1)

检查一下......

regex for minimum work/day -> /([0-1]\d{0,1})|(2[0-4])/
regex for minimum work/week -> /([0-4]\d{0,1})|(5[0-6])/