# Category: validation

## how to trigger a validation of child component from parent component OnSubmit Angular 4?

I Have forms like this, in parent i am including multiple child components each child component is formgroup. now i need to check all this child forms validation on parent form when user click OnSubmit. How should i trigger child form validations from parent on submit. I have used FormBuilder in each childcomponent. I am able to do validation when user click on child fields but if user doesn’t enter anything or touched anything and […]

## Looking for help a regex that prevents special characters except ‘, space and – in the string but disallows them at the start

I have been scouring the internet for answers to this regex question and I have come quite close to getting it but I think I am missing one or two more groups to prevent the special characters at the start and end of the string. It is for use in angularJS and the full specification is a string of letters that cannot be longer than 20 characters, will only allow -,’ and space as the […]

I have an input field on my HTML page and I want to put some validations on it. Limit the number of characters that the field can hold (say 6 maximum). The field can only contain numeric characters. the field is disabled if it does not contain 6 Zeros (000000). The field should be editable if it contains 6 Zeros (000000). <input type=”text” ng-model=”testfield” placeholder=”XXXXXX” ng-maxlength=”6″ ng-disabled=”testfield !=’000000′” ng-required=”testfield ==’000000′” ng-pattern=”/^[0-9]{6}$/”> Source: AngularJS ## Not validating new controls after submitting form in angularjs We have a form which we are submitting on save button. There are some validation firing on save. We are submitting form using$scope.isSubmitted= true and $scope.watch on$scope.isSubmitted for error highlighting After submitting and validating the form, if there is any new controls add to form on the basis of ng-if condition the new controls are also validated. So my question is how to prevent new controls which being added after submitting the form […]

I need to create mask for input field where user can input symbols only like in template: “01ABC2345-67-89” – two digits, then three chars, then four digits, then “-“(or if he input digit, “-” add automatically), then two digits, “-” and again two digits. There is my code – my mask filter only numbers. Ho to create regexp for my objective? html: <html ng-app=”app”> <head> <meta charset=”UTF-8″> <title>serialNumber mask</title> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js”></script> <script type=”text/javascript” src=”main.js”></script> </head> […]

## ngMessage/ngMessages do not work , AngularJS

I’m trying to validate a phone number using the ngMessages and ngMessage directives, but I am facing two problems: The “Invalid Input” message is shown only after the pattern’s expression is met and the user continued typing. The “required” message is not shown when the input is empty. I want the “Invalid Input” to be shown as soon as the user starts typing, and not only after the pattern is met. I don’t understand what […]

## angular schema form image upload accepting all file types

I have used the this plugin Angular Schema Form and all the things are working as expected but for image upload i need to have validations so as to allow the users input only images. although the schema contains an accept attribute in the properties for image upload as follows: { “type”: “object”, “properties”: { “text1”: { “type”: “string”, “title”: “Untitled Text field”, “name”: “text1”, “url”: “http://localhost/image/upload/img59b7c29f1622b.jpeg” }, “file2”: { “type”: “object”, “format”: “file”, “title”: […]

## Form validation in angularjs doesn’t work

I wrote a form validation in angularjs but it does not work. When I send form with empty fields form has class ‘ng-valid’ and ‘ng-hide’ doesn’t remove from error. <form name=”form” ng-submit=”createUser(user)” novalidate> <div class=”form-group”> <label for=”name”>Nazwa użytkownika:</label> <input type=”text” name=”name” id=”name” class=”form-control” ng.model=”user.name” required=””> <div ng-show=”form.$submitted || form.name.$touched”> <div ng-show=”form.name.$error.required”>Podaj nazwę użytkownika.</div> </div> </div> <div class=”form-group”> <label for=”email”>Adres e-mail:</label> <input type=”email” name=”email” id=”email” class=”form-control” ng.model=”user.email”> <div ng-show=”form.$submitted || form.email.$touched”> <span ng-show=”form.email.$error.required”>Podaj adres e-mail.</span> <span […]