Rinto Andrews Rinto Andrews - 1 year ago 96
iOS Question

Regex to Check Numbers, Space, ( ) +

I am writing a IOS app , for that i need regx to detect Numbers, Space , ( ) +

[newText isMatchedByRegex:@"^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"]

Answer Source

You can find the whitespace through this below code,

 NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];

And you can find the number by,

-(BOOL)only_number :(NSString *)text_string
      NSCharacterSet* notDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
      if ([text_string rangeOfCharacterFromSet:notDigits].location == NSNotFound)
            return FALSE;
            return TRUE;


Note: Here the Key is NSCharacterSet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download