判断密码长度

//写一个label

    self.label=[[UILabel alloc] initWithFrame:CGRectMake(100, 50, 100, 30)];

    self.label.layer.borderWidth=1;

    self.label.backgroundColor=[UIColor clearColor];

    [self.window addSubview:self.label];

    [self.label release];

    self.label.text=@"";


//写一个textField

    self.testField=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 100, 30)];

    [self.window addSubview:self.testField];

    [self.testField release];

    self.testField.layer.cornerRadius=10;

    self.testField.layer.borderWidth=1;

  只要输入就会执行length5方法  

[self.testField addTarget:self action:@selector(length5:) forControlEvents:UIControlEventEditingChanged];


-(void)length5:(UITextField *)textField

{

    if (textField.text.length>5) {

        self.label.text=@"密码长度不符合标准";

    }

    else{

        self.label.text=@"密码长度符合标准";

    }

    }



你可能感兴趣的:(判断密码长度)