![](/img/trans.png)
[英]Automatically takes a space after 4 letters in text input field in react-native
[英]Automatically takes a '/'(slash) in textInput field using react-native
如果我在文本輸入字段中輸入文本,那么它會自動在月和年之間使用“/”(斜線)。
這是我的代碼:
handleMMYYYY = (text) => {
this.setState({ MMYYYY: text })
}
<TextInput
underlineColorAndroid="transparent"
autoCapitalize="none"
placeholder="MM/YYYY"
style={{textAlign:'center'}}
placeholderTextColor="grey"
returnKeyType='next'
onChangeText={this.handleMMYYYY}
onSubmitEditing={(event)=>{
this.refs.third.focus();
}}
/>
一種方法可能是這樣
handleMMYYYY = (text) => {
formated = text;
if(formated.length==2){
//formated = text +'/';
if(this.state.getCardDate.indexOf('/') == -1){
formated = text +'/';
}
}
this.setState({ getCardDate: formated })
}
不靈活,但我能想到的最簡單的。
已經有很多反應組件可以做到這一點。 這稱為屏蔽輸入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.