title: How to make textfield that allows only numbers from 1 to 31 [Objective C]
body: <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  if([newString length]&gt;=1)
  {
      NSString *sepStr=[newString substringToIndex:1];
      return !([sepStr length]&gt;1);
  }
  
  if ([string length] == 0 &amp;&amp; range.length &gt; 0){
      textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
      return NO;
  }
  NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
  if ([string stringByTrimmingCharactersInSet:nonNumberSet].length &gt; 0)return YES;}
  
  - (IBAction)btnc:(id)sender {
  
      if([_textfield.text length]&gt;2)
      {
          UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"WARNING" message:@"Please Fill The Mendatory Fields." preferredStyle:UIAlertControllerStyleAlert];
          [self presentViewController:alert animated:YES completion:nil];
          UIAlertAction* OK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
                               {
                               }];
          [alert addAction:OK];
  
      }
      else{
          desViewController *face=[self.storyboard instantiateViewControllerWithIdentifier:@"REar"];
          [self.navigationController pushViewController:face animated:YES];
      }
  </code></pre>
  
  <p>I have an app in which I want to enter a numeric value in <code>UITextField</code>. But I want to allow only 2 digit numbers to be entered and from 1 to 31 only . Any idea how I can modify this to accept only a numeric value limited to 2 digits and from 1 to 31 only?</p>