My Problem is i have to do Like User can enter values in Range ... My range is coming from json
here's my code whatever i tried ... here a,b is my start range and b is end range user can enter values better this range not out of range
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField)
{
NSData *data = [((MDCFlowDetails *)_flow).flow_data dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSString *a = [json objectForKey:@"startrange"];
NSString *b = [json objectForKey:@"endrange"];
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSString *expression = @"^([0-9]+)?(\\.([0-9]{1,2})?)?$";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:expression
options:NSRegularExpressionCaseInsensitive
error:nil];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:newString
options:0
range:NSMakeRange(0, [newString length])];
if (numberOfMatches == 0)
return NO;
}
return YES;
}
I think it can be done simply by just checking
length
of textfield.Put a condition on low and high end of range when user enter text in textfield.
See below code: