From 8871e43ecbd5a03ca89d42c4b6dc7d111f277a0c Mon Sep 17 00:00:00 2001 From: Aman Ansar Date: Sat, 7 Aug 2021 03:56:53 +0530 Subject: [PATCH 1/3] don't allow invalid characters --- src/pages/settings/AddSecondaryLoginPage.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/AddSecondaryLoginPage.js b/src/pages/settings/AddSecondaryLoginPage.js index 3731aa043e3c..414959c19787 100755 --- a/src/pages/settings/AddSecondaryLoginPage.js +++ b/src/pages/settings/AddSecondaryLoginPage.js @@ -71,6 +71,7 @@ class AddSecondaryLoginPage extends Component { }; this.formType = props.route.params.type; this.submitForm = this.submitForm.bind(this); + this.onSecondaryLoginChange = this.onSecondaryLoginChange.bind(this); this.validateForm = this.validateForm.bind(this); this.phoneNumberInputRef = null; @@ -80,6 +81,15 @@ class AddSecondaryLoginPage extends Component { Onyx.merge(ONYXKEYS.USER, {error: ''}); } + onSecondaryLoginChange(login) { + if (this.formType === CONST.LOGIN_TYPE.EMAIL) { + this.setState({login}); + } else if ( + this.formType === CONST.LOGIN_TYPE.PHONE && (/^(\+)(\d)*$/.test(login) || login === '')) { + this.setState({login}); + } + } + /** * Add a secondary login to a user's account */ @@ -135,7 +145,7 @@ class AddSecondaryLoginPage extends Component { ref={el => this.phoneNumberInputRef = el} style={styles.textInput} value={this.state.login} - onChangeText={login => this.setState({login})} + onChangeText={this.onSecondaryLoginChange} keyboardType={this.formType === CONST.LOGIN_TYPE.PHONE ? CONST.KEYBOARD_TYPE.PHONE_PAD : undefined} returnKeyType="done" From 079fe6a740831b57b213d65b656bd7ce28e39a4e Mon Sep 17 00:00:00 2001 From: Aman Ansar Date: Sun, 8 Aug 2021 16:55:29 +0530 Subject: [PATCH 2/3] improvement --- src/pages/settings/AddSecondaryLoginPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/AddSecondaryLoginPage.js b/src/pages/settings/AddSecondaryLoginPage.js index 414959c19787..cec0c83f2f24 100755 --- a/src/pages/settings/AddSecondaryLoginPage.js +++ b/src/pages/settings/AddSecondaryLoginPage.js @@ -85,7 +85,7 @@ class AddSecondaryLoginPage extends Component { if (this.formType === CONST.LOGIN_TYPE.EMAIL) { this.setState({login}); } else if ( - this.formType === CONST.LOGIN_TYPE.PHONE && (/^(\+)(\d)*$/.test(login) || login === '')) { + this.formType === CONST.LOGIN_TYPE.PHONE && (CONST.REGEX.DIGITS_AND_PLUS.test(login) || login === '')) { this.setState({login}); } } From efb48075d2a723749c237b89a434c91357335cda Mon Sep 17 00:00:00 2001 From: Aman Ansari Date: Fri, 13 Aug 2021 02:48:43 +0530 Subject: [PATCH 3/3] update --- src/pages/settings/AddSecondaryLoginPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/AddSecondaryLoginPage.js b/src/pages/settings/AddSecondaryLoginPage.js index cec0c83f2f24..69b83bff888d 100755 --- a/src/pages/settings/AddSecondaryLoginPage.js +++ b/src/pages/settings/AddSecondaryLoginPage.js @@ -84,8 +84,8 @@ class AddSecondaryLoginPage extends Component { onSecondaryLoginChange(login) { if (this.formType === CONST.LOGIN_TYPE.EMAIL) { this.setState({login}); - } else if ( - this.formType === CONST.LOGIN_TYPE.PHONE && (CONST.REGEX.DIGITS_AND_PLUS.test(login) || login === '')) { + } else if (this.formType === CONST.LOGIN_TYPE.PHONE + && (CONST.REGEX.DIGITS_AND_PLUS.test(login) || login === '')) { this.setState({login}); } }