Skip to content

Instantly share code, notes, and snippets.

@iKenndac
Created January 31, 2018 13:42
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 iKenndac/d9919def053af6fc14c4a3e5e5233c88 to your computer and use it in GitHub Desktop.
Save iKenndac/d9919def053af6fc14c4a3e5e5233c88 to your computer and use it in GitHub Desktop.
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if string.count == 0 { return true } //Backspace
if string.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) != nil { return false } // Non-numerics
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment