Guest User

Untitled

a guest
Apr 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. dateFormat(text) {
  2. if (text.match(/^d{2}$/) !== null) {
  3. this.value = text + '/';
  4. } else if (text.match(/^d{2}/d{2}$/) !== null) {
  5. this.value = text + '/';
  6. }
  7. this.setState({birthdate: this.value});
  8. }
  9.  
  10. onChangeText={(text) => this.dateFormat(text)}
  11.  
  12. onChangeText(text){
  13. if (text.match(/^d{2}$/) !== null) {
  14. var value = text + '/';
  15. this.setState({birthdate: value})
  16. } else if (text.match(/^d{2}/d{2}$/) !== null) {
  17. var value = text + '/';
  18. this.setState({birthdate: value});
  19. } else {this.setState({birthdate:text})}
  20. }
  21.  
  22. 'use strict';
  23.  
  24. var React = require('react-native');
  25. var {
  26. AppRegistry,
  27. StyleSheet,
  28. Text,
  29. View,
  30. TextInput
  31. } = React;
  32.  
  33. var SampleApp = React.createClass({
  34.  
  35. getInitialState(){
  36. return {
  37. birthdate: ''
  38. }
  39. },
  40.  
  41. onChangeText(text){
  42. if (text.match(/^d{2}$/) !== null) {
  43. var value = text + '/';
  44. this.setState({birthdate: value})
  45. } else if (text.match(/^d{2}/d{2}$/) !== null) {
  46. var value = text + '/';
  47. this.setState({birthdate: value});
  48. } else {this.setState({birthdate:text})}
  49. },
  50.  
  51. render: function() {
  52. return (
  53. <View style={styles.container}>
  54. <TextInput
  55. value={this.state.birthdate}
  56. onChangeText={ (text) => this.onChangeText(text) }
  57. style={styles.textInput}
  58. />
  59. <Text>{this.state.birthdate}</Text>
  60. </View>
  61. );
  62. }
  63. });
  64.  
  65. var styles = StyleSheet.create({
  66. container: {
  67. flex: 1,
  68. marginTop:60
  69. },
  70. textInput: {
  71. height:70,
  72. backgroundColor: '#ddd'
  73. }
  74. });
  75.  
  76. AppRegistry.registerComponent('SampleApp', () => SampleApp);
Add Comment
Please, Sign In to add comment