#鸿蒙通关秘籍#ArkUI中如何在TextInput组件中设置只能输入小写字母

HarmonyOS
2024-11-27 12:35:13
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
系统小英雄

TextInput组件可以通过.inputFilter()方法限制输入。在下例中,将输入限制为小写字母:

TextInput({ text: this.text, placeholder: 'input your word...' })
    .placeholderColor(Color.Red)
    .placeholderFont({ size: 14, weight: 400 })
    .caretColor(Color.Blue)
    .width('95%')
    .height(40)
    .margin(20)
    .fontSize(14)
    .fontColor(Color.Black)
    .inputFilter('[a-z]', (e) => {
        console.log(JSON.stringify(e))
    })
    .onChange((value: string) => {
        this.text = value
    })
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

分享
微博
QQ
微信
回复
2024-11-27 13:45:21
相关问题
HarmonyOS 输入只能输入字母和数字
1131浏览 • 1回复 待解决