UITextField — Restrict textfield to a certain character (iOS)

// MARK: - UITextFieldDelegatelet allowedCharacters = CharacterSet(charactersIn:”0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz”).invertedfunc textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {let components = string.components(separatedBy: allowedCharacters)
let filtered = components.joined(separator: "")if string == filtered {
return…

--

--

--

iOS Developer, Triple graduated, Passionate, Love workout, blogger

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Jpeg Viewer App For Mac

Documentation Markup in iOS(XCode)

UINavigationController iOS

Android dev tip#1 — Tooltips

How to Stack and Layer Views With ZStack in SwiftUI

Person looking at an iPhone

My experience as an iOS Developer Intern

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mr.Javed Multani

Mr.Javed Multani

iOS Developer, Triple graduated, Passionate, Love workout, blogger

More from Medium

Basic Operators in Swift

A Swift transition

Swift Combine -Understanding [Publisher, Subscriber, Operator]

Preventing Invalid Characters from Being Entered in a UITextField