allow only to enter english characters in iPhone UITextField

六月ゝ 毕业季﹏ 提交于 2019-12-12 17:06:32

问题


I want to allow user to enter only english alphabets and characters. How can i prevent user from entering other characters than english.


回答1:


Check out UIKeyboardType - there is an option to support only ASCII (UIKeyboardTypeASCIICapable).

Also, there are options in the UITextFieldDelegate protocol that could allow you to selectively filter input. Take a look at:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;



来源:https://stackoverflow.com/questions/2475405/allow-only-to-enter-english-characters-in-iphone-uitextfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!