3
I’m developing a regex validation using the System.ComponentModel.DataAnnotations
and RegularExpression
from Asp.net mvc C#, in this regex it is necessary to validate unlimited duration time in hours and the time must be greater than 00:00
, that is, values can be accepted from 00:01
within minutes(59) and seconds(59).
I managed to get as far as: \d{1,}:[0-5][0-9]
04:00 -- true
00:01 -- true
00:23 -- true
00:04 -- true
04:00 -- true
01:00 -- true
23:00 -- true
21:00 -- true
1:00 -- true
00:61 -- false
00:00 --> problema
57:59 -- true
123:59 -- true
As this is a form, I am only validating a time and not a set of values, as shown in the following image:
I’d like a little help on how to deny the value 00:00
in this regex. As it is in a Regularexpression in Dataannotations, or linked in my model "Duration", I need it to fit in just one validation:
[RegularExpression("^(\d{1,}:[0-5][0-9])$", ErrorMessageResourceName = "CampoObrigatorio")]
public string Duracao { get; set; }
My regex validates only hh:mm, where hours can be infinite.
– Cleber
is in C#, is in a System.ComponentModel.Dataannotations Regularexpression
– Cleber
Yes it is to check.
– Cleber
I got it, I added it in the body of the question, it’s just a time and not a set of times.
– Cleber
Good evening, did any of the answers solve your problem? If yes, mark the answer that best helped you as correct, if you do not specify what the problem occurred when trying the proposed solutions.
– Guilherme Nascimento