日期文本输入 React Native 的自动反斜杠?

Tam*_*fer 7 textinput react-native

有谁知道如何创建一个文本输入,当您开始输入时,它会自动允许一定数量的数字,并为数字自动分隔反斜杠。

DD / MM / YYYY(我不打算使用日期选择器或库)。

小智 5

尝试这个反应组件:

https://github.com/benhurott/react-native-masked-text

安装

npm install react-native-masked-text --save

用法

render() {
//the type is required but options is required only for some specific types.
  return (
    <TextInputMask
      refInput={(ref) => this.myDateText = ref;}
      type={'datetime'}
      options={{
        format: 'DD-MM-YYYY HH:mm:ss'
      }}
    />
  )
}
Run Code Online (Sandbox Code Playgroud)

有一种面膜适合您:

日期时间:使用具有时刻格式的日期时间掩码(默认 DD/MM/YYYY HH:mm:ss)。它接受选项(请参阅本文档后面的内容)。