Browse Source

Added simple client-side validation for phones

Closes #1161
master
Igor Zhukov 9 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'])
$scope.sendCode = function () { $scope.sendCode = function () {
$timeout.cancel(nextTimeout) $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({ ErrorService.confirm({
type: 'LOGIN_PHONE_CORRECT', type: 'LOGIN_PHONE_CORRECT',
country_code: $scope.credentials.phone_country, country_code: $scope.credentials.phone_country,

11
app/partials/desktop/import_contact_modal.html

@ -2,13 +2,16 @@
<div class="md_simple_modal_body"> <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> <h4 my-i18n="contact_import_modal_title"></h4>
<div class="md-input-group" my-labeled-input> <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" my-i18n="contact_import_modal_phone"></label> <label class="md-input-label" ng-switch="importContactForm.phone.$invalid && importContactForm.phone.$touched">
<input class="md-input" my-focused type="text" ng-model="importContact.phone" my-submit-on-enter /> <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>
<div class="md-input-group" my-labeled-input> <div class="md-input-group" my-labeled-input>

Loading…
Cancel
Save