From af137f8867dce643232c8edfa92294b8f87b3b89 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 2 May 2017 18:30:46 +0100 Subject: [PATCH] Validate phone number on login To prevent confusion when accidently inputting mxid or email. Fixes https://github.com/vector-im/riot-web/issues/3637 --- src/components/structures/login/Login.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/structures/login/Login.js b/src/components/structures/login/Login.js index 315a0ea242..a3635177e2 100644 --- a/src/components/structures/login/Login.js +++ b/src/components/structures/login/Login.js @@ -23,6 +23,9 @@ import url from 'url'; import sdk from '../../../index'; import Login from '../../../Login'; +// For validating phone numbers without country codes +const PHONE_NUMBER_REGEX = /^[0-9\(\)\-\s]*$/; + /** * A wire component which glues together login UI components and Login logic */ @@ -125,7 +128,16 @@ module.exports = React.createClass({ }, onPhoneNumberChanged: function(phoneNumber) { - this.setState({ phoneNumber: phoneNumber }); + // Validate the phone number entered + if (!PHONE_NUMBER_REGEX.test(phoneNumber)) { + this.setState({ errorText: 'The phone number entered looks invalid' }); + return; + } + + this.setState({ + phoneNumber: phoneNumber, + errorText: null, + }); }, onServerConfigChange: function(config) {