Validate NSString for Hexadecimal value
Swift 5
extension String {
var isHexNumber: Bool {
filter(\.isHexDigit).count == count
}
}
print("text1".isHexNumber) // false
print("aa32".isHexNumber) // true
print("AD1".isHexNumber) // true
Does this method work for you?
NSString *string = @"FF";
NSCharacterSet *chars = [[NSCharacterSet
characterSetWithCharactersInString:@"0123456789ABCDEF"] invertedSet];
BOOL isValid = (NSNotFound == [string rangeOfCharacterFromSet:chars].location);