更新时间:2023-02-21 12:30:39
创建一个验证方法,如下所示:
Create one method for validation like this:
-(BOOL) validateAlphabets: (NSString *)alpha
{
NSString *abnRegex = @"[A-Za-z]+"; // check for one or more occurrence of string you can also use * instead + for ignoring null value
NSPredicate *abnTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", abnRegex];
BOOL isValid = [abnTest evaluateWithObject:alpha];
return isValid;
}
现在检查你想要的验证:
Now check for the validation where you want like this:
bool checkAlphabets = [self validateAlphabets:txtfirstname.text];
if(!checkAlphabets)
{
NSLog(@"Not Matches..");
}
else
{
NSLog(@"Matches..");
}