How do I restrict UITextField to English only? (Stopping Chinese pinyin input)

I am building an app for release in Taiwan so it will be mostly in Chinese however the usernames must be English. I’m not sure how to stop Chinese characters from being input. So far I have restricted the length of the username to 12 characters and the characters must be in the set defined below:

#define ACCEPTABLE_CHARACTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

I implemented the – (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string method and now my UITextField works for the two conditions above. However, although a Chinese character is not in the set it still appears due to pinyin being used to type it is english. i.e. 李 is li so I am able to type l then i and then the Chinese character 李 appears. Is there anyway to get around this? Any help would be greatly appreciated. Thanks

  • Searching on a Background Thread
  • UISlider that snaps to a fixed number of steps (like Text Size in the iOS 7 Settings app)
  • How to free a component in Android / iOS
  • Native iOS app: What do I put in Facebook's developer “iPhone App Store ID” under Settings, Basic?
  • MPMediaItemPropertyArtwork causes crash (weird issue)
  • NSFetchedResultsController calls didChangeObject delete instead of update
  • 2 Solutions Collect From Internet About “How do I restrict UITextField to English only? (Stopping Chinese pinyin input)”

    Try to set the keyboard type of the input field

    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectZero];
    tf.keyboardType = UIKeyboardTypeASCIICapable;

    used this

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
           NSCharacterSet *numbersOnly = [NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"];
           NSCharacterSet *characterSetFromTextField = [NSCharacterSet   characterSetWithCharactersInString:string];
        BOOL stringIsValid = [numbersOnly isSupersetOfSet:characterSetFromTextField];
            return yes;
           return no;