可以用這個例子:
-(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;
}
沒有留言:
張貼留言