开发者

How I disable the alpha, alpha numeric and special character in UITextField?

开发者 https://www.devze.com 2022-12-24 03:12 出处:网络
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

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.


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];
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号