Question: I have a Rails application with Resque doing background jobs on multiple servers. The jobs are different in terms of their resource needs, so I would like to limit the amount of jobs of particular type, each server can do. I want to be able to have multiple servers query the same Redis database. 

Here is the scenario:
I have Server-1 and Server-2 connected to the same Redis database.

1) Each server should take 3 "Encoding" jobs and 5 "Parsing" jobs max (8 jobs total). 

2) At a given moment Redis-server will have 10 jobs in "Encoding" queue and 12 jobs in "Parsing" queue available for Resque workers to process. I have 2 servers running, quering the same database. 

QUESTION: How can I prevent Server-1 from taking 8 "Encoding" jobs and Server-2 taking the rest? In other words, how to restrict Server-1 to taking only 3 jobs from "Encoding" queue and 5 jobs from "Parsing" queue and have Server-2 do the same? 

I want to keep the code universal so that I can deploy it to multiple servers without individual tweaking..

Answer: 
```
NSString* val = [[textField text] stringByReplacingCharactersInRange:range withString:string];
    NSCharacterSet *allowedCharacterSet = [NSCharacterSet decimalDigitCharacterSet];
    if ([[string componentsSeparatedByCharactersInSet:[allowedCharacterSet invertedSet]] count] > 1 || [val length] > 5) {
        return NO;
    }

```
I have modified @iDev's answer to work for digitals and ".":

```
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
     // Check for non-numeric characters
     NSUInteger lengthOfString = string.length;
     for (NSInteger index = 0; index < lengthOfString; index++) {
         unichar character = [string characterAtIndex:index];
         if ((character < 48) && (character != 46)) return NO; 
         // 48 unichar for 0, and 46 unichar for point
         if (character > 57) return NO; 
         // 57 unichar for 9
     }
     // Check for total length
     NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
     if (proposedNewLength > 6)
         return YES;
     return YES; 
 }

```