How to check user input for proper formatting

This is what I came up with so far

private void CheckFormatting()
{
    StringReader objReaderf = new StringReader(txtInput.Text);
    List<String> formatTextList = new List<String>();

     do
     {
         formatTextList.Add(objReaderf.ReadLine());
     } 
     while (objReaderf.Peek() != -1);

     objReaderf.Close();
     for (int i = 0; i < formatTextList.Count; i++)
     {

     } 
}

That it is intended is to verify that the user has entered their information in this format Gxx: xx: xx: xx JGxx, where "x" can be any integer.

As you can see, the user enters his data into a multi-line text field. Then I take this data and enter it into the list. the next part is where I am stuck. I am creating a for loop to go through the list line by line, but I think I will also need to go through each character of the line by character. How should I do it? or is there a faster way to do this?

early

+3
source share
4 answers

Try it.

    if (!System.Text.RegularExpressions.Regex.IsMatch("your_text", "G[0-9]{2}:[0-9]{2}:[0-9]{2}:[0-9]{2} JG[0-9]{2}"))
    {
        //Error!
    }
+1

- .

+1

G\d\d:\d\d:\d\d:\d\d: JG\d\d ( ) System.Text.RegularExpressions

+1

, , .

, :, .

, asp.net? , asp.net , .

.

<asp:textbox id="textbox1" runat="server"/>
<asp:RegularExpressionValidator id="valRegEx" runat="server"
    ControlToValidate="textbox1"
    ValidationExpression="[0-9]*"
    ErrorMessage="* Your entry is not a valid number."
    display="dynamic">*
</asp:RegularExpressionValidator>
+1

Source: https://habr.com/ru/post/1749254/


All Articles