tags:

views:

236

answers:

2

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.

+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
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
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
zoul,The above method is appropriate for character, but it shall works for special characters?
RRB
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