diff --git a/__tests__/screens/__snapshots__/RegisterScreen.test.js.snap b/__tests__/screens/__snapshots__/RegisterScreen.test.js.snap
index 461e156..d7ab818 100644
--- a/__tests__/screens/__snapshots__/RegisterScreen.test.js.snap
+++ b/__tests__/screens/__snapshots__/RegisterScreen.test.js.snap
@@ -33,6 +33,14 @@ exports[`Testing RegisterScreen renders as expected 1`] = `
}
}
>
+
,
+ text: '',
+ validValue: -1,
+ };
+ }
+
+ handleInput(newText) {
+ this.setState({ text: newText.trim() }, () => {
+ this.validateText(this.state.text, this.props.validorRegex);
+ });
+ }
+
+ handleUpdate() {
+ if (this.state.validValue) {
+ this.setState({ errorTextArea: });
+ this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#80FF80', borderWidth: 2 }] });
+ } else {
+ this.setState({ errorTextArea: {this.props.errorMessage} });
+ this.setState({ styleInUse: [styles.InputFieldStyle, { borderColor: '#FF9999', borderWidth: 2 }] });
+ }
+ }
+
+ validateText(text, regexTest) {
+ if (regexTest.global) {
+ console.warn('validateText()', 'Regexp using global flag! The results may be wrong.');
+ } else {
+ // Do nothing
+ }
+
+ const isValid = regexTest.test(text);
+
+ if (isValid) {
+ console.warn('Valido');
+ this.setState({ validValue: true }, () => {
+ this.handleUpdate();
+ });
+ } else {
+ console.warn('Invalido');
+ this.setState({ validValue: false }, () => {
+ this.handleUpdate();
+ });
+ }
+ }
+
+ render() {
+ return (
+
+ {this.props.header.toUpperCase()}
+ this.handleInput(text)}
+ />
+
+ {this.state.errorTextArea}
+
+
+ );
+ }
+}
+
+GenericField.propTypes = {
+ header: PropTypes.string.isRequired,
+ message: PropTypes.string.isRequired,
+ validorRegex: PropTypes.string.isRequired,
+ errorMessage: PropTypes.string.isRequired,
+};
+
+// export default GenericField;
diff --git a/src/screens/RegisterScreen.js b/src/screens/RegisterScreen.js
index e1cd6b3..7a86294 100644
--- a/src/screens/RegisterScreen.js
+++ b/src/screens/RegisterScreen.js
@@ -33,6 +33,7 @@ import CpfField from '../components/CpfField';
import NameField from '../components/NameField';
import EmailField from '../components/EmailField';
import PasswordField from '../components/PasswordField';
+import GenericField from '../components/GenericField';
import PhoneField from '../components/PhoneField';
import DropdownComponent from '../components/DropdownComponent';
import MunicipalDistrict from '../components/MunicipalDistrict';
@@ -119,6 +120,7 @@ export default class RegisterScreen extends React.Component {
super(props);
this.state = {
+ teste: '',
email: '',
name: '',
password: '',
@@ -246,6 +248,9 @@ export default class RegisterScreen extends React.Component {
logInfo(FILE_NAME, 'render()',
`State of register page: ${JSON.stringify(this.state, null, 2)}`);
+ // Testing regex list
+ const sixMoreWordCharRegex = /\w{6,}/;
+
return (
@@ -253,6 +258,16 @@ export default class RegisterScreen extends React.Component {
+ this.setState({ teste: newValue })}
+ onChange={console.warn('OnChange', this.state.teste)}
+ regexInput={sixMoreWordCharRegex}
+ errorMessage="Está errado!"
+ />
+
CPF