Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dateFormat(text) {
- if (text.match(/^d{2}$/) !== null) {
- this.value = text + '/';
- } else if (text.match(/^d{2}/d{2}$/) !== null) {
- this.value = text + '/';
- }
- this.setState({birthdate: this.value});
- }
- onChangeText={(text) => this.dateFormat(text)}
- onChangeText(text){
- if (text.match(/^d{2}$/) !== null) {
- var value = text + '/';
- this.setState({birthdate: value})
- } else if (text.match(/^d{2}/d{2}$/) !== null) {
- var value = text + '/';
- this.setState({birthdate: value});
- } else {this.setState({birthdate:text})}
- }
- 'use strict';
- var React = require('react-native');
- var {
- AppRegistry,
- StyleSheet,
- Text,
- View,
- TextInput
- } = React;
- var SampleApp = React.createClass({
- getInitialState(){
- return {
- birthdate: ''
- }
- },
- onChangeText(text){
- if (text.match(/^d{2}$/) !== null) {
- var value = text + '/';
- this.setState({birthdate: value})
- } else if (text.match(/^d{2}/d{2}$/) !== null) {
- var value = text + '/';
- this.setState({birthdate: value});
- } else {this.setState({birthdate:text})}
- },
- render: function() {
- return (
- <View style={styles.container}>
- <TextInput
- value={this.state.birthdate}
- onChangeText={ (text) => this.onChangeText(text) }
- style={styles.textInput}
- />
- <Text>{this.state.birthdate}</Text>
- </View>
- );
- }
- });
- var styles = StyleSheet.create({
- container: {
- flex: 1,
- marginTop:60
- },
- textInput: {
- height:70,
- backgroundColor: '#ddd'
- }
- });
- AppRegistry.registerComponent('SampleApp', () => SampleApp);
Add Comment
Please, Sign In to add comment