0

I'm new to RegularExpression in asp.net MVC 2. It's been whole day looking for the right syntax trial and error.

If anyone could help?

Here is the problem:

minimum hours work/day -> allowable float number but not greater than 24

minimum hours work/week -> allowable float number but not greater than 56


I'm trying to create regex that will accept if the input is integer or float number but not greater than 24.

Also if the input has white space print ErrorMessage = " White space is not allowed"


VIEW

<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; }

Anyone please help.

2
  • 1
    Welcome to stackoverflow. You should post examples of the code that you wrote that pertains to your question. A good example would be the regex pattern you're using and how you're using it in javascript. Commented Jun 27, 2013 at 13:57
  • I posted the sample codes above Sir. Thank You very much Commented Jun 27, 2013 at 14:32

1 Answer 1

1

check this...

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])/
Sign up to request clarification or add additional context in comments.

3 Comments

[RegularExpression("/([0-1]\d{0,1})|(2[0-4])/", ErrorMessage = "Must not greater than 24")] public double dblMinHrs { get; set; } | my visual studio encounter runtime error
Remove the '/' at the beginning and end. And you probably need to escape the '\', try '\\'.
Anyone please help. Thanks in advance god bless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.