The goal of c is to help create a regular expression for the format (#, #)

A user enters their credit hours per course in my UITextField in this format ....

4,3,4,3,3

(4 credit hours for the 1st year, 3 credit hours for the 2nd year, etc.)

Conditions: The user can enter only MIN during 1 course and MAX 5, credit hours should be separated by a comma, except for the last, the line should contain only numbers and commas (without letters, etc.) in this order.

I am trying to display an error message if the conditions are violated. I think I will need to create regExp. I am not sure how to create it, since the user can enter 2 courses this way ... (3,4), and everything will be fine. (for example, it cannot follow strict formats such as a phone number).

+4
source share
1 answer

Instead of letting the user enter what they think is right and then tell them that they are wrong at the end, consider using the textField:shouldChangeCharactersInRange:replacementString: text field delegate method. This does not stop you from using the regular expression, but you can also filter the characters entered by the user to prevent any letters and immediately inform the user when they make an error.

+2
source

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


All Articles