Set the maximum number of characters in UITextField in RxSwift


        //Maximum number of characters for TextField
            .map { text in
                if let text = text, text.count > 4 {
                    return String(text.prefix(4))
                } else {
                    return text ?? ""
            .bind(to: textField.rx.text) //If you enter the same number that has already been entered, the next event will not flow and you will not loop infinitely.
            .disposed(by: disposeBag)


――I haven't tried it, but in the case of Japanese input, this may not work, so it seems that you need to consider it separately. --You can also use textField.rx.controlEvent (.editingChanged) etc.


RxSwift/RxCocoa: prevent UITextField from having more than … characters [iOS] Set the maximum number of characters in UITextField [Swift] How to set a character limit for UITextField

Recommended Posts

Set the maximum number of characters in UITextField in RxSwift
[Java] Check the number of occurrences of characters
Set the number of seconds for fast forward and rewind in ExoPlayer
How to change the maximum and maximum number of POST data in Spark
[Order method] Set the order of data in Rails
Count the number of occurrences of a string in Ruby
Set the time zone in the JVM of your Azure application
Count the number of digits after the decimal point in Java
A program that counts the number of words in a List
[Java] Delete the specified number of characters from the end of StringBuilder
Find the number of days in a month with Kotlin
[Swift] When you want to know if the number of characters in a String matches a certain number ...
{The first consecutive 10-digit prime number in the value of e} .com
The milliseconds to set in /lib/ of Java jre is UTC
Order of processing in the program
Number of digits in numeric item
Dynamically increase the number of elements in a Java 2D array (multidimensional array)
How to set the indent to 2 single-byte spaces in the JAXB implementation of the JDK
Code of the part where server.servlet.session.timeout is set in spring.session.timeout in spring-boot2 system
How to find the total number of pages when paging in Java
Find the maximum and minimum of the five numbers you entered in Java
Get the result of POST in Java
The identity of params [: id] in rails
How to determine the number of parallels
The story of AppClip support in Anyca
About the number of threads of Completable Future
The story of writing Java in Emacs
Write the movement of Rakefile in the runbook
Set the source of the library set as a dependency in IntelliJ as a separate module of the project
How to set environment variables in the properties file of Spring boot application
[Java] Handling of JavaBeans in the method chain
The story of making ordinary Othello in Java
About the idea of anonymous classes in Java
Measure the size of a folder in Java
Set the time of LocalDateTime to a specific time
Feel the passage of time even in Java
[Java] Judgment by entering characters in the terminal
Get your version number in the Android app
Import files of the same hierarchy in Java
I checked the number of taxis with Ruby
[Java] Integer information of characters in a text file acquired by the read () method
Find the greatest common divisor and least common multiple of any number of integers in Ruby
How to set the log level to be displayed in the release version of orhanobut / logger
Find the maximum and minimum values out of the 5 numbers entered in Java (correction ver)
Summary of how to use the proxy set in IE when connecting with Java