title: Limiting NSString to numbers as well as # if chars entered. (code included)
body: <p>I have searched the site for my answer, 
  however I think it is also how I got myself into this problem.</p>
  
  <p>I'm trying to limit my 1 and only text field to 10 characters and only numbers.</p>
  
  <p>Below is code mostly off other questions on this site.
  What I am trying to do is mash this code together for my limits</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
      NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
      NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
      NSString *newString = [myTextField.text stringByReplacingCharactersInRange:range withString:filtered]; 
      return !([newString length] &gt; 10);
  }
  </code></pre>
  
  <p>There are no problems with my build until I click my textfield... but I get a green arrow warning stating " thread stopped at breakpoint 1 "
  I've tried a few different things now, but now feel I am stumped, I'm hoping this is something real easy for someone here...</p>
  
  <p>they will work individually (one or the other) with the code below, but I can't seem to get them working together.</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
      NSString *newString = [myTextField.text stringByReplacingCharactersInRange:range withString:string];
      return !([newString length] &gt; 10);
  }
  </code></pre>
  
  <p>This will limit my input to 10
  and ... </p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
      NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
      NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
      return [string isEqualToString:filtered];
  }
  </code></pre>
  
  <p>This also restricts my input to numbers only with no problems.
  provided I defined LEGAL as only numbers...</p>
  
  <p>I just can't seem to get them to work together...
  Can anyone help me with this one ???</p>