Development encountered this problem, think or summarize, just beginning to limit the Uitextfield keyboard for
Uikeyboardtypeasciicapable, but when the user switched the Chinese keyboard still does not solve the problem, so I added the input box to listen to the event, get input box The latest input content, detect whether the input content contains Chinese, if the Chinese is replaced with an empty string, The specific implementation is as follows:
InfoView.userTF.keyboardType = uikeyboardtypeasciicapable;
Listening for input content
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (textfilededitchanged:)
name:@ "Uitextfieldtextdidchangenotification"
Object:infoView.userTF];
-(void) textfilededitchanged: (nsnotification*) notification
{
Uitextfield*textfield = Notification.object;
Nsstring*str = Textfield.text;
for (int i = 0; i<str.length; i++)
{
nsstring*string = [Str substringfromindex:i];
NSString *regex = @ "[\u4e00-\u9fa5]{0,}$"; Chinese
2. Stitching predicates
Nspredicate *predicatere1 = [Nspredicate predicatewithformat:@ "self matches%@", regex];
3. Match string
BOOL Resualt = [PredicateRe1 evaluatewithobject:string];
if (Resualt)
{
Is Chinese replaced with an empty string
str = [str stringbyreplacingoccurrencesofstring:[str substringfromindex:i] withstring:@ ""];
}
}
Textfield.text = str;
}
IOS limit input box cannot be entered in Chinese