Last active
August 23, 2019 15:54
-
-
Save commanda/406fd80dbe09928d8de6940ad1ff7cb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var isHexColorString: Bool { | |
do { | |
let regex = try NSRegularExpression(pattern: "^#?[0-9A-Fa-f]{6}$") | |
return regex.matches(in: self, options: [], range: wholeRange).isEmpty == false | |
} catch { | |
return false | |
} | |
} | |
} | |
extension String { | |
var wholeRange: NSRange { | |
return NSRange(location: 0, length: self.count) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment