- this code only allows numbers in text mode
If you configure iOS 4.1 and later, you can use UIKeyboardTypeDecimalPad. If you need to support older versions, you need a decimal point and you no longer need anything, you will need to create a custom keyboard.
If you want to filter other keys without deleting them, assign an object as a delegate to the text field. This object should contain the following code:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet]; return([text stringByTrimmingCharactersInSet:nonNumberSet].length > 0)
for the alphabet, others you use the code above with this code ^ [0-9a-zA-Z]. I think this is useful for you. deck day
source share