I have a UITextField
where the user should type a float number. I want to check that such number has a certain format I receive, for instance "dddd.dd", where "d" is a digit. The format could change at any moment, since I receive it as input as well, so for example I may want to check at another moment that "," character is used for decimals, to say another example.
Taking into account that the text
you read from the UITextField
is of String
type (optional), what should be the best way to accomplish this?
- A predicate with the format provided. Then evaluate the input string. Then converting to number.
- Try to convert to number. If success (how characters for separating decimals would be handled this way?), then check the format with
NumberFormatter
? - Any other and/or better way?