Rinto Andrews Rinto Andrews - 1 month ago 6
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

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;
      }
      else
      {
            return TRUE;
      }

}

Note: Here the Key is NSCharacterSet.