Last active
December 10, 2018 20:21
-
-
Save keehun/78da2bac4cae86a6f2e0b7c8f144c882 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
func isValidNumeral(input4: String) -> Bool { | |
let numbers = CharacterSet.decimalDigits | |
let rangeOfInvalidCharacters = input4.rangeOfCharacter(from: numbers.inverted) | |
return rangeOfInvalidCharacters == nil | |
} | |
let string1 = "qwerty12345" | |
let string2 = "qwerty" | |
let string3 = "12345" | |
print("\"\(string1)\" only contains numbers: \(isValidNumeral(input4: string1))") | |
/// "qwerty12345" only contains numbers: false | |
print("\"\(string2)\" only contains numbers: \(isValidNumeral(input4: string2))") | |
/// "qwerty" only contains numbers: false | |
print("\"\(string3)\" only contains numbers: \(isValidNumeral(input4: string3))") | |
/// "12345" only contains numbers: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment