-1

In my project user's can type out the username they want. I will like to restrict this field where they can only use letters, numbers and a underscore (like Instagram). I've searched the internet for hours but can not come up with anything. How can I do this? Thank you in advance!

1
  • 1
    Have a look at this question which fully describes it :) Commented Apr 17, 2018 at 21:50

1 Answer 1

2
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let s = NSString(string: textField.text ?? "").replacingCharacters(in: range, with: string) guard !s.isEmpty else { return true } let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .none return numberFormatter.number(from: s)?.intValue != nil } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.