Commit 4c25c98b52af32479f9b682b399a65f9bd1f4d1e

Authored by Kuldeep Arora
1 parent 2bfb51a502
Exists in master

email validation

app/partials/accountSetting/accountSetting.Controller.js
... ... @@ -68,29 +68,51 @@
68 68  
69 69 })
70 70 }
  71 + $scope.accountdata = {};
  72 + $scope.accountdata.userName = '';
  73 + $scope.accountdata.status = true;
71 74  
72 75 $scope.addAccount = function(){
73 76 $('#demo-modal').css('display', 'block');
74 77 }
75 78  
76 79 $scope.cancelAddAccount = function(){
77   - $scope.accountdata = {};
  80 + $scope.accountdata = {};
78 81 $('#demo-modal').css('display', '');
79 82 }
  83 +
80 84 $scope.additionalAccnObj = {};
81 85 $scope.createAddAccount = function(){
82   - AccountSettingService.addAdditionalAccount($scope.accountdata).then(function(result) {
83   - getAdditionalAccounts();
84   - $scope.accountdata = {};
85   - $('#demo-modal').css('display', '');
86   - toastr.success(''+result.success+'', {
  86 + if ($scope.accountdata.userName === '') {
  87 + toastr.error('Please enter all the fields.', {
87 88 closeButton: true
88 89 })
89   - })
90   -
  90 + }else{
  91 + if (validateEmail($scope.accountdata.userName)) {
  92 + AccountSettingService.addAdditionalAccount($scope.accountdata).then(function(result) {
  93 + getAdditionalAccounts();
  94 + $scope.accountdata = {};
  95 + $('#demo-modal').css('display', '');
  96 + toastr.success(''+result.success+'', {
  97 + closeButton: true
  98 + })
  99 + })
  100 + }else{
  101 + toastr.error('Please enter valid email.', {
  102 + closeButton: true
  103 + })
  104 + }
  105 + }
  106 +
91 107 }
92   -
93   - $scope.changeStatus = function(id, index){
  108 +
  109 + /*Validate Email */
  110 + function validateEmail(email) {
  111 + var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  112 + return re.test(email);
  113 + }
  114 +
  115 + $scope.changeStatus = function(id, index){
94 116 event.stopPropagation();
95 117 var id = id;
96 118 var statusData = "status=" + $scope.additionalAccounts[index].status + "&id=" + $scope.additionalAccounts[index].id + "&firstName=" + $scope.additionalAccounts[index].firstName
... ...
app/partials/accountSetting/accountSetting.html
... ... @@ -191,7 +191,7 @@
191 191  
192 192 <div class="col-md-6">
193 193 <div class="pull-left" style="width: calc(140% - 170px);">
194   - <input type="text" ng-model="accountdata.userName" placeholder="XYZfbo@gmail.com" class="form-control" >
  194 + <input type="email" ng-model="accountdata.userName" placeholder="XYZfbo@gmail.com" class="form-control" required >
195 195 </div>
196 196  
197 197 <div class="clearfix"></div>
... ... @@ -230,7 +230,7 @@
230 230 </div>
231 231  
232 232 <div class="modal-footer" style="border-top: 0;">
233   - <button type="button" class="btn btn-primary step step-1" data-step="1" ng-click="createAddAccount()">Save</button>
  233 + <button type="button" class="btn btn-primary step step-1" data-step="1" ng-click="createAddAccount()" >Save</button>
234 234 <button type="button" class="btn btn-default" ng-click="cancelAddAccount()" data-dismiss="modal">Cancel</button>
235 235 </div>
236 236 </div>
... ...