Home > Software engineering >  Validation Expression of a field converted to an expected input
Validation Expression of a field converted to an expected input

Time:12-21

I really don't work with ASP.NET or C# so please excuse the naivety of my question. I normally develop using Python but for a certain project I need to decipher some C# and ASP.NET scripts. Here is a validator for a date input field as I understand;

ValidationExpression="^([0-2][0-9]|(3)[0-1])(\.)(((0)[0-9])|((1)[0-2]))(\.)\d{4}$"

My question is what would be a valid date input with this validator at hand?

I can guess the input but only partially, as I understand '\d{4}$' stand for a 4 digit number. Its formatted as 'd m Y' but I'm not sure what '(.)' stands for and would 1 digit days/months would be 01-05 or 1-5 etc.

In general a few examples of expected inputs would be a great help, and guessing is quite inefficent because I already need to guess lots of other parameters.

Again sorry for the probable simplicity of my question :).

Full element as it might be needed;

<div >
   <asp:TextBox ID="txtBirthDate" runat="server" CssClass="form-control date-mask datePicker" Text='<%#Item.BirthDate %>'></asp:TextBox>
   <asp:RequiredFieldValidator ValidationGroup="vgReservation" Display="Dynamic" CssClass="help-block" ID="rfvBirthDate" runat="server" ErrorMessage="Doğum Tarihi gereklidir." ControlToValidate="txtBirthDate" InitialValue=""></asp:RequiredFieldValidator>
   <asp:RegularExpressionValidator ValidationGroup="vgReservation" Display="Dynamic" CssClass="help-block" ID="revBirthDate" runat="server" ErrorMessage="Doğum Tarihi geçerli bir tarih olmaldır." ControlToValidate="txtBirthDate" ValidationExpression="^([0-2][0-9]|(3)[0-1])(\.)(((0)[0-9])|((1)[0-2]))(\.)\d{4}$"></asp:RegularExpressionValidator>
</div>

CodePudding user response:

If you paste your regex into one of the many online testers, e.g.

https://regex101.com/

It will break it down for you and explain the capture groups.

In this case, it looks like you tryig to validate dates like 10.2.2022, although I don't think the regex is particularly correct.

  • Related