英数字のみ
TextField("Input", text: $input)
.onChange(of:input, perform: filter)
func filter(value: String) {
let validCodes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
let sets = CharacterSet(charactersIn: validCodes)
input = String(value.unicodeScalars.filter(sets.contains).map(Character.init))
if 10 < input.count {
input = String(input.prefix(10))
}
}
https://zenn.dev/yorifuji/articles/swiftui-textfield-filter
댓글
댓글 쓰기