Browse Source

Added simple client-side validation for phones

Closes #1161
master
Igor Zhukov 8 years ago
parent
commit
9b763a16cb
  1. 14
      app/js/controllers.js
  2. 11
      app/partials/desktop/import_contact_modal.html

14
app/js/controllers.js

@ -171,6 +171,20 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -171,6 +171,20 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.sendCode = function () {
$timeout.cancel(nextTimeout)
var fullPhone = ($scope.credentials.phone_country || '') + ($scope.credentials.phone_number || '');
var badPhone = !fullPhone.match(/^[\d\-+\s]+$/);
if (!badPhone) {
fullPhone = fullPhone.replace(/\D/g, '');
if (fullPhone.length < 7) {
badPhone = true;
}
}
if (badPhone) {
$scope.progress.enabled = false
$scope.error = {field: 'phone'}
return
}
ErrorService.confirm({
type: 'LOGIN_PHONE_CORRECT',
country_code: $scope.credentials.phone_country,

11
app/partials/desktop/import_contact_modal.html

@ -2,13 +2,16 @@ @@ -2,13 +2,16 @@
<div class="md_simple_modal_body">
<form class="modal_simple_form" ng-submit="doImport()">
<form class="modal_simple_form" ng-submit="doImport()" name="importContactForm">
<h4 my-i18n="contact_import_modal_title"></h4>
<div class="md-input-group" my-labeled-input>
<label class="md-input-label" my-i18n="contact_import_modal_phone"></label>
<input class="md-input" my-focused type="text" ng-model="importContact.phone" my-submit-on-enter />
<div class="md-input-group" my-labeled-input ng-class="{'md-input-error': importContactForm.phone.$invalid && importContactForm.phone.$touched}" my-labeled-input>
<label class="md-input-label" ng-switch="importContactForm.phone.$invalid && importContactForm.phone.$touched">
<span ng-switch-when="true" my-i18n="login_incorrect_number"></span>
<span ng-switch-default my-i18n="contact_import_modal_phone"></span>
</label>
<input class="md-input" my-focused type="tel" ng-model="importContact.phone" ng-pattern="/^[-\+\(\)\d]{7,32}$/" my-submit-on-enter name="phone" />
</div>
<div class="md-input-group" my-labeled-input>

Loading…
Cancel
Save