Created
August 12, 2019 15:53
-
-
Save xieweiAlex/92f1ac8fedf3a55679f30c4cdd93f7e5 to your computer and use it in GitHub Desktop.
Check string is alphanumeric
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 isAlphanumeric: Bool { | |
return !isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"".isAlphanumeric // false
"abc".isAlphanumeric // true
"123".isAlphanumeric // true
"ABC123".isAlphanumeric // true
"iOS 9".isAlphanumeric // false