在我的应用程序中。我想用特殊字符验证文本字段,
前任。如果用户按?从键盘比用户无法输入?在文本字段中,
请任何人建议,我该怎么做?
在我的应用程序中。我想用特殊字符验证文本字段,
前任。如果用户按?从键盘比用户无法输入?在文本字段中,
请任何人建议,我该怎么做?
像下面这样尝试它会帮助你。它只接受字母
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//For avoiding user to enter non digital number..
if([[string stringByTrimmingCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] isEqualToString:@""])
{
return NO;
}
else
{
return YES;
}
}
检查这个
利用
- (BOOL) textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)textEntered
看看这是否有效:
-(NSString *) formatIdentificationNumber:(NSString *)string
{
NSCharacterSet * invalidNumberSet = [NSCharacterSet characterSetWithCharactersInString:@"\n_!@#$%^&*()[]{}'\".,<>:;|\\/?+=\t~` "];
NSString * result = @"";
NSScanner * scanner = [NSScanner scannerWithString:string];
NSString * scannerResult;
[scanner setCharactersToBeSkipped:nil];
while (![scanner isAtEnd])
{
if([scanner scanUpToCharactersFromSet:invalidNumberSet intoString:&scannerResult])
{
result = [result stringByAppendingString:scannerResult];
}
else
{
if(![scanner isAtEnd])
{
[scanner setScanLocation:[scanner scanLocation]+1];
}
}
}
return result;
}