Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow spaces and special chars in phone number username #6293

Merged
merged 6 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function isValidUSPhone(phoneNumber) {
* @returns {Boolean}
*/
function isNumericWithSpecialChars(input) {
return /^\+?\d*$/.test(input.replace(/[()-]/g, ''));
return /^\+?\d*$/.test(input.replace(/((?!\n)[()-\s\t])/g, ''));
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/pages/signin/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class LoginForm extends React.Component {
return;
}

if (!Str.isValidEmail(this.state.login) && !Str.isValidPhone(this.state.login)) {
const phoneLogin = this.state.login.replace(/((?!\n)[()-\s\t])/g, '');
const isValidPhoneLogin = Str.isValidPhone(phoneLogin);

if (!Str.isValidEmail(this.state.login) && !isValidPhoneLogin) {
if (isNumericWithSpecialChars(this.state.login)) {
this.setState({formError: 'messages.errorMessageInvalidPhone'});
} else {
Expand All @@ -93,7 +96,7 @@ class LoginForm extends React.Component {
});

// Check if this login has an account associated with it or not
fetchAccountDetails(this.state.login);
fetchAccountDetails(isValidPhoneLogin ? phoneLogin : this.state.login);
}

render() {
Expand Down