2016年5月5日 星期四

NSPredicate

如何比對user輸入的字串,讓他符合我限定的!?

可以用這個例子:

-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
   
    if (textField == self.sideFirstPassField) {
        NSString *resultString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        NSString *strictString = @"[a-zA-Z0-9]*";
        BOOL predicate = [[NSPredicate predicateWithFormat:@"SELF MATCHES%@",strictString] evaluateWithObject:resultString];
        return predicate;
    }
    return YES;

}

沒有留言:

張貼留言