Password validation in UITextField in iOS

前端 未结 11 1097
有刺的猬
有刺的猬 2020-12-01 12:54

I have 1 UITextfield for password in my iPhone application.

I want to validate this textfield with the following validation.

  • Must be at le
11条回答
  •  一生所求
    2020-12-01 13:18

    Use the control:isValidObject: method of the NSTextFieldDelegate protocol which allows you to validate the value of a NSTextField. Assuming you have all your interface builder bits and pieces configured correctly, you might do something like this:

    @interface PreferencesController : NSWindowController  {
        IBOutlet NSTextField *username, *password;
    }
    
    @end
    
    @implementation PreferencesController
    
    - (BOOL)control:(NSControl *)control isValidObject:(id)object
    {
        if (control == password) {
          // Perform validation and return YES or NO
        }
    
        return YES;
    }
    
    @end
    

提交回复
热议问题