iPhone – Replication Paste to Restrict Strings in Digital Text Fields

I have a text box and I want the user to only enter numbers. I implemented a numeric keypad there. However, if someone puts my app in the background and copy from other apps Some string and return to my application and paste it, it will successfully paste the string content into my numeric text field. How can I limit this situation?
@theChrisKent is very close, but there is a better way. Use the delegate method -textView:shouldChangeTextInRange:replacementText:. Check if replacementText contains any non-digits, and if it is, return NO.

I have a text box and I want the user to enter only numbers. I implemented a numeric keypad there. However, if Someone put my app in the background and copy some string from other app and return to my app and paste it, it will successfully paste the string content into my digital text field. How can I restrict This situation?

@theChrisKent is very close, but there is a better way. Use the delegate method -textView: shouldChangeTextInRange: replacementText:. Check whether the replacementText contains any non-digits, if it is, then Return NO.

Leave a Comment

Your email address will not be published.