Hi, Thanks in advanced. I want to disable or also i have does not give permission entering the alpha, alpha numeric and special character in UITextField i mean when user enter the alpha and special character in text box then i want to quickly message box pop-up to showing him u only have use 0,1-9 digit. Please give me any source code and tutorials on it.
views:
236answers:
2
+1
A:
Call setKeyboardType:
on your UITextField, and pass one of the UIKeyboardType
constants. I’m not sure which one fits your description.
- (void)awakeFromNib
{
[textField setKeyboardType:UIKeyboardTypeNumberPad];
}
Todd Yandell
2010-03-27 09:09:28
Todd Yandell,I already changing the UIKeyboardTypeNumberPad in design view but then also UITextField allow me to enter alpha and special characters in text field.
RRB
2010-03-27 09:14:05
A:
Take a look at the UITextFieldDelegate protocol. There’s a method called textField:shouldChangeCharactersInRange:replacementString:
where you can validate the replacement string and return NO
if it falls into one of the disallowed sets. As for the validation itself, see the method rangeOfCharacterFromSet:
of the NSString class and the NSCharacterSet class.
zoul
2010-03-27 10:00:28
zoul,The above method is appropriate for character, but it shall works for special characters?
RRB
2010-03-27 10:12:36
There’s an `invertedSet` method on `NSCharacterSet`, so that you can check if the string contains some characters from the inverted set of `decimalDigitCharacterSet`. If yes, you disallow the string. That should allow only the decimal digits (if that’s what you want).
zoul
2010-03-27 10:36:29