- (BOOL)NumberValidation:(NSString *)string {
NSUInteger newLength = [string length];
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return (([string isEqualToString:filtered])&&(newLength <= 3));
}
in your button action event just use this like bellow...
-(IBAction)ButtonPress{
if ([self NumberValidation:yourString]) {
NSLog(@"Macth here");
}
else {
NSLog(@"Not Match here");
}
}
http://stackoverflow.com/questions/9477563/how-to-enter-numbers-only-in-uitextfield-and-limit-maximum-length
http://stackoverflow.com/questions/9477563/how-to-enter-numbers-only-in-uitextfield-and-limit-maximum-length
No comments:
Post a Comment