UITextField should have only positive number

前端 未结 5 1691
执念已碎
执念已碎 2021-01-07 06:09

I need to validate a UITextField. I want only positive integers to be entered in it. How can I achieve that?

5条回答
  •  醉酒成梦
    2021-01-07 06:45

    From the top of my head:

    Convert the string into a integer using [textField.text intValue] and check it is positive. I would do it in the - (BOOL)textFieldShouldEndEditing:(UITextField *)textField method from the UITextFieldDelegate protocol.

    Cheers

提交回复
热议问题