Skip to content

Instantly share code, notes, and snippets.

@commanda
Last active August 23, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commanda/406fd80dbe09928d8de6940ad1ff7cb9 to your computer and use it in GitHub Desktop.
Save commanda/406fd80dbe09928d8de6940ad1ff7cb9 to your computer and use it in GitHub Desktop.
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