angularjs-validation

AngularJS password confirmation noMatch working but form is $invalid?

可紊 提交于 2019-12-08 09:37:19
问题 I am using this code to make password input and confirm password input to match correctly Javascript: var app = angular.module('app', []); app.directive('validPasswordC', function() { return { require: 'ngModel', scope: { reference: '=validPasswordC' }, link: function(scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function(viewValue, $scope) { var noMatch = viewValue != scope.reference ctrl.$setValidity('noMatch', !noMatch) }); scope.$watch("reference", function(value) {; ctrl.$setValidity(

AngularJS 'controller as' and form.$valid

眉间皱痕 提交于 2019-12-05 05:24:57
I want to check if a form is valid inside an angular controller. This seems straightforward when using $scope, but I can't get it to work with the 'controller as' syntax. When I attempt to access form.$valid I get the error message "Cannot read property '$valid' of undefined" . plunkr: http://plnkr.co/edit/w54i1bZVD8UMhxB4L2JX?p=preview HTML <div ng-app="demoControllerAs" ng-controller="MainController as main"> <form name="contactForm" novalidate> <p> <label>Email</label> <input type="email" name="email" ng-model="main.email" required /> </p> <p> <label>Message</label> <textarea name="message"

kendo ui, angular require validation for numeric text box

倾然丶 夕夏残阳落幕 提交于 2019-12-04 17:12:38
I am trying to use a kendo numeric text box with angular validation (ng-required) however I'm not able to get it working. The ng-required attribute on this element has no effect on the form validation status. From my understanding, the reason why this doesn't work is because kendo numeric text box uses k-ng-model to store it's value, whereas the angular validation works only with ng-model. Has anyone else seen this issue, are there any workarounds? I have found a workaround that involves using the kendo-numeric-text-box along with a hidden input field which makes use of ng-model. <input data

How can i count the number of errors on Form?

情到浓时终转凉″ 提交于 2019-12-04 03:14:52
FIDDLE How can i count the number of errors made on form ? HTML <div ng-show="form.$submitted && form.$invalid"> Sorry but 3 errors have been made. </div> One way you could do this by using the specific count of a specific error criteria, required , pattern etc.. that are available as a part of form's $error[prop] array. In your case you could try using form.$error.required.length :- <div ng-show="form.$submitted && form.$invalid"> Sorry but {{form.$error.required.length}} errors have been made. </div> Demo You could add a function on the controller which can determine the number of errors on

Validation on text on alphabets enter

杀马特。学长 韩版系。学妹 提交于 2019-12-03 08:56:10
问题 Any one use AngulerJS Validation on TextBox. So that only enter alphabets. 回答1: Depending on what you want: Alphabets and blankspace: ng-pattern="/^[a-zA-Z\s]*$/" Alphabets no blankspace: ng-pattern="/^[a-zA-Z]*$/" 回答2: I guess all the other answers using ng-pattern are correct but just to mention, the use of ng-model is compulsory with ng-pattern . The complete input can be: <input type="text" ng-pattern ="/^[a-zA-Z\s]*$/" ng-model="Name" /> This will accept the alphabets and the spaces only

Why does adding additional AngularJS validation directives cause $asyncValidators to run multiple times?

空扰寡人 提交于 2019-12-01 05:57:39
问题 Why does adding additional AngularJS validation directives cause $asyncValidators to run multiple times on page load? I created a custom directive which implements $asyncValidators. This is the basic structure of that custom directive: myApp.directive('userSaved',['$q','userLookup',function($q, userLookup){ return { restrict: 'A', require: 'ngModel', link: function(scope, elem, attrs, ctrl){ ctrl.$asyncValidators.userSaved = function(modelValue, viewValue) { // do stuff } } } }]); The

angularjs ng-minlength validation is not working, form still being submitted

≯℡__Kan透↙ 提交于 2019-11-27 20:45:47
问题 I am trying to submit the form on only successful validation. validation is working for required but not working for ng-minlength form input is invalid but form is still being submitted. <form name="myForm" ng-submit="count = count + 1" ng-init="count=0" ng-app> <div class="control-group" ng-class="{error: myForm.mobile.$invalid}"> <label class="control-label" for="mobile">Mobile</label> <div class="controls"> <input type="text" name="mobile" placeholder="07XXXXXXXXX" ng-model="mobile" ng

AngularJS Dropdown required validation

元气小坏坏 提交于 2019-11-27 18:16:15
Following is my code snippet. I want to validate my dropdown using angular. <td align="left" width="52%"> <span class="requiredSmall">*</span> <select class="Sitedropdown" style="width: 220px;" ng-model="selectedSpecimen().serviceID" ng-options="service.ServiceID as service.ServiceName for service in services"> <option value="" ng-selected="selected">Select Service</option> </select> </td> Valid means: Valid values can be anything but "Select Service", it is my default value. Like other ASP.net Require field validator DefaultValue="0" for dropdown, so here My dropdown will be bound from the

Validate phone number using angular js

前提是你 提交于 2019-11-27 12:29:56
Want to set phone-number to 10 digits, How can I do this using Angular js. This is what I have tried: <form class="form-horizontal" role="form" method="post" name="registration" novalidate> <div class="form-group" ng-class="{'has-error': registration.phone.$error.number}"> <label for="inputPhone" class="col-sm-3 control-label">Phone :</label> <div class="col-sm-9"> <input type="number" class="form-control" ng-minlength="10" ng-maxlength="10" id="inputPhone" name="phone" placeholder="Phone" ng-model="user.phone" ng-required="true"> <span class="help-block" ng-show="registration.phone.$error

validate natural input number with ngpattern

℡╲_俬逩灬. 提交于 2019-11-27 07:22:34
I use ng-pattern="/0-9/" to set price_field do not accept decimal number . But when I input natural number (from 0 to 9999999), ng-show gets activated with Not valid number! . Where did I go wrong?. Please help. <form name="myform" data-ng-submit="create()"> <input type="number" name="price_field" data-ng-model="price" require ng-pattern="/0-9/" <span ng-show="myform.price_field.$error.pattern">Not valid number!</span> <input type="submit" class="btn"> </form> Chickenrice The problem is that your REGX pattern will only match the input "0-9". To meet your requirement (0-9999999), you should