kotlin - 如何使用 Android 两种方式绑定在 EditText 中设置正则表达式?
问题描述
您好,我想知道如何使用 Android 双向绑定在 EditText 中设置正则表达式
我的正则表达式
val VALID_PASSWOLD_REGEX_ALPHA_NUM: Pattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*#?&])[A-Za-z[0-9]$@$!%*#?&]{8,32}$")
我的视图模型
val passwordText = MutableLiveData<String>("")
我的 xml
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@null"
android:onTextChanged="@{(text, start, before, count) -> signUpViewModel.onPasswordChanged(text)}"
android:hint="@string/sign_up_password"
android:text="@={signUpViewModel.passwordText}"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/name_text" />
我短暂的想法是应该从onTextChange接收并处理,但我想不出更好的方法,所以我问了这个问题
你能介绍我另一种方式吗?
解决方案
我刚刚使用 android:onTextChanged 谢谢
推荐阅读
- ruby-on-rails - 使用 equals-to 和 twiddle-wakka 针对同一版本在 gem 依赖项之间运行 Bundle 更新时发生冲突
- python - 如果使用常量初始化器不需要指定形状?
- scala - 以编程方式安排作业防止重复作业
- java - 在类 'org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean' 中没有定义 1 个参数的构造函数
- extjs - ExtJS — 在 app/ 下组织文件
- zsh - 如何在 shell 中获取字符串路径?
- android - 获取 gradle 构建的 aapt2 参数?
- openstreetmap - 反向地理编码中的城市名称
- excel - Set Connection = Application.OpenConnection 使其他用户的 Excel 崩溃
- handlebars.js - 获取一个对象值,其键是车把中的数字?