The method should return TRUE if the NSString is something like @\"{A5B8A206-E14D-429B-BEB0-2DD0575F3BC0}\" and FALSE for a NSString like @\"bla bla bla\"
I am using
Consider the shortened UUID format. Use code below:
-(BOOL)isValidUUID:(NSString*)uuidString{
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
if (uuid ) {
return YES;
}
NSError *error;
NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:@"[^0-9|^a-f]" options:NSRegularExpressionCaseInsensitive error:&error];
NSArray *matches = [reg matchesInString:uuidString options:NSMatchingReportCompletion range:NSMakeRange(0, uuidString.length)];
if (matches.count == 0 && (uuidString.length == 4 || uuidString.length ==8) ) {
return YES;
}else{
return NO;
}
}