ios - How do I detect if a text field has text in it rather than a numerical value? -
I have a text field that enters the user number and turns it into an integer.
The keyboard set is one of the decimal number and the paste function is still enabled, even though the user can paste text into it.
I want to set it to change a label on "Error" if the user enters a numeric value in it.
I do not want to disable the paste function because I still want the user to have the ability to copy and paste their numerical values in their app.
If you want to apply the restriction only enter numeric values, then If the string is numeric, then no yes EDET: Adam's answer is best for check text, only numeric or not. UITextField
- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) Category Replacement String: (NSString *) string {NSCharacterSet * nonNumberSet = [[ NSCharacterSet decimalDigitCharacterSet] invertedSet]; Return ([string string bitimeter converter inset: non-numberet]. Length = gt;) || [String avastostring: @ ""]; }
Comments
Post a Comment