I am really new to ios development. while validating a text field i must ensure that it contains only 0-9 and special characters like * and #. Please help me out.
- (BOOL)validate:(NSString *)string{
NSString *exp = @"^([0-9]+)?(\\.([0-9]{1,2})?)?$";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:exp options:NSRegularExpressionCaseInsensitive error:nil];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, [string length])];
if (numberOfMatches == 0)
return NO;
return YES;
}