I need to validate first and last name from Credit card.
For example: “Lange Norton” or “LANGE NORTON”
I use this code:
NSString *nameRegex = @"^[A-Z][a-z]*[\pL\pM\p{Nl}][A-Z][a-z]*$";
NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex];
return [nameTest evaluateWithObject:nameSurname];
And I have a problem with whitespace.
“Unknown escape sequence ‘\p'”
What should I do?
I think you missed some curly brackets
if you also need whitspace add
\sYou can find a list of those properties (the
\p{L}\p{M}\p{Nl}stuff) here on regular-expressions.infoAdditionally I don’t think your expression is correct.
Your string needs to start with
[A-Z]followed by[a-z]*(can also be zero) and then only one of those[\p{L}\p{M}\p{Nl}]another uppercase ASCII letter followed by lowercase letters.What happens if the persons name is “René Müller”?