0

I'm trying to validate a FULL NAME , i.e "John Smith" and allow spaces ( 1 or more)

I'm using the following code: My regex pattern looks like this?

[A-Za-z_.- ]{2,39}";

I have seen in previous posts to add a space to match on space. I have also tried prefixing the space with back slashes. I added a 'space' after the '-'.

When I run my code

NSString *FilterString = @"[A-Za-z_.- ]{2,39}";
NSString *nameRegex = FilterString;
NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex];
return [nameTest evaluateWithObject:self];

I get the following error:

Can't do regex matching, reason: Can't open pattern U_REGEX_INVALID_RANGE (string John Smith, pattern [A-Za-z_.- ]{2,39}, case 0, canon 0)

What is the correct pattern to match spaces? What is wrong with the above?

Jon
  • 1,608
  • 7
  • 25
  • 38

0 Answers0