angularjs - javascript validation of space and empty field -


i want validate form if user type white space aur leave field empty..

the problem code word perfect when put space in textbox , show validation..but when space empty redirect next page

this controller

 $scope.valid=  function (){         var fname = $("#fname").val();         var lname = $("#lname").val();         var email = $("#email").val();         var contact = $("#contact").val();           if( fname.indexof(" ") !== -1)         {             $scope.modalvalue = "spaces not allowed";registermodal.show();         }         else if( lname.indexof(" ") !== -1){             $scope.modalvalue = "spaces not allowed";registermodal.show();         }         else if( lname.indexof(" ") !== -1){             $scope.modalvalue = "spaces not allowed";registermodal.show();         }         else if( contact.indexof(" ") !== -1){             $scope.modalvalue = "spaces not allowed";registermodal.show();         }     } 

this resigter.html

   <ons-row style="margin-top:45px;text-align: center">             <ons-col>                 <div>                     <input class="textbox" id="fname" name="fname"     ng-model="fname" type="text" placeholder="first name" ng-trim='false' required/>                 </div>             </ons-col>         </ons-row>         <ons-row style="margin-top:15px;text-align: center">             <ons-col>                 <div>                     <input class="textbox" id="lname" ng-model="lname" name="lname" type="text" placeholder="last name" required/>                 </div>             </ons-col>         </ons-row>         <ons-row style="margin-top:15px;text-align: center">             <ons-col>                 <div>                     <input class="textbox" id="email" ng-model="email" type="email" placeholder="email" required/>                 </div>             </ons-col>         </ons-row>         <ons-row style="margin-top: 15px;font-family:mai;font-size: 1.2em;text-align: center">             <ons-col>                 <div class="">                     <span style="padding: 10px">                         <input id="radio1" type="radio" ng-model="gender" value="1" checked="checked"><label for="radio1">male</label>                     </span>                     <span style="padding: 10px">                         <input id="radio1" type="radio" ng-model="gender" value="2" ><label for="radio1">female</label>                     </span>                 </div>             </ons-col>         </ons-row>         <ons-row style="margin-top:15px;text-align: center">             <ons-col>                 <div>                     <input class="textbox" ng-model="password" type="password" placeholder="password" required/>                 </div>             </ons-col>         </ons-row>          <ons-row style="margin-top:15px;text-align: center">             <ons-col>                 <div>                     <input class="textbox" id="contact" ng-model="contact" type="text" placeholder="contact number" required/>                 </div>             </ons-col>         </ons-row>          <ons-row style="text-align:center;margin-top:10px">             <ons-col>                 <input type="button" class="loginbutton buttoncolor" value="register" ng-click="register() ; valid()" />             </ons-col>         </ons-row>      <ons-row>         <ons-modal var="registermodal">             <div>{{modalvalue}}</div>             <ons-button ng-click="showlogin1()" style="margin:20px;">close</ons-button>         </ons-modal>     </ons-row> 

why don't try simple approche :

if( fname!= "" && fname!= " ")     {         $scope.modalvalue = "spaces not allowed";registermodal.show();     } 

and same others textfield


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -