Friday, March 10, 2017

How to set the validation for Full name field using Objective C?

Full name field validation using Objective C code.

if ([self validate:self.fullnamefield.text] == 0)
{
        NSLog(@"Please Enter Valid User Name");

}

- (BOOL)validate:(NSString *)string
{
    NSError *error             = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z .]" options:0 error:&error];
    
    NSUInteger numberOfMatches = [regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, [string length])];
    
    return numberOfMatches == string.length;

}

No comments:

Post a Comment