How to use the @angular/forms.Validators.minLength function in @angular/forms

To help you get started, we’ve selected a few @angular/forms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bfwg / angular-spring-starter / frontend / src / app / signup / signup.component.ts View on Github external
ngOnInit() {
    this.route.params
      .pipe(takeUntil(this.ngUnsubscribe))
      .subscribe((params: DisplayMessage) => {
        this.notification = params;
      });
    // get return url from route parameters or default to '/'
    this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
    this.form = this.formBuilder.group({
      username: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(64)])],
      password: ['', Validators.compose([Validators.required, Validators.minLength(3), Validators.maxLength(32)])],
      firstname: [''],
      lastname: ['']
    });
  }
github eosrio / simpleos / src / app / dashboard / send / send.component.ts View on Github external
checkExchangeAccount() {
		const memo = this.sendForm.get ( 'memo' );
		const acc = this.sendForm.value.to.toLowerCase ();

		if (this.knownExchanges.includes ( acc )) {

			console.log(this.aService.activeChain['exchanges'][acc].pattern.toString());
			const aux = new RegExp("^[0-9]+$","gm");
			if (this.aService.activeChain['exchanges'][acc]) {
				if(this.aService.activeChain['exchanges'][acc].memo_size) {
					memo.setValidators ( [ Validators.required , Validators.pattern ( this.aService.activeChain['exchanges'][acc].pattern ), Validators.minLength ( parseInt(this.aService.activeChain[ 'exchanges' ][ acc ].memo_size, 10 )) , Validators.maxLength ( parseInt(this.aService.activeChain[ 'exchanges' ][ acc ].memo_size, 10 )) ] );
				}else{
					memo.setValidators ( [ Validators.required , Validators.pattern ( this.aService.activeChain['exchanges'][acc].pattern)]);
					console.log('only pattern');
				}
			} else {
				memo.setValidators ( [ Validators.required ] );
			}
			this.memoMsg = 'required';

			memo.updateValueAndValidity ();
			console.log(memo);
		} else {
			this.memoMsg = 'optional';
			memo.setValidators ( null );
			memo.updateValueAndValidity ();
		}
github OasisDigital / angular-enterprise-example / libs / employee-management / src / employee-fields / employee-fields.component.ts View on Github external
constructor(fb: FormBuilder) {
    this.fg = fb.group({
      'first_name': ['', Validators.required],
      'last_name': ['', [Validators.required, Validators.minLength(3)]],
      'email': [''],
      'hours_worked': ['', [Validators.required, Validators.pattern('[0-9]+')]],
      'hourly_wage': ['', [Validators.required, Validators.pattern('[0-9]+')]]
    });
  }
github mprove-io / mprove / src / app / components / space / login / login.component.ts View on Github external
buildForm(): void {
    this.loginForm = this.fb.group({
      email: [
        null,
        Validators.compose([
          Validators.required,
          Validators.email,
          Validators.maxLength(255)
        ])
      ],
      password: [
        null,
        Validators.compose([
          Validators.required,
          Validators.minLength(6),
          Validators.maxLength(255)
        ])
      ]
    });
  }
github suricate-io / suricate / frontend / src / app / modules / authentication / register / register.component.ts View on Github external
this.authenticationService.logout();

    this.passwordControl = this.formBuilder
        .control(
            '',
            [Validators.required, Validators.minLength(3)]
        );

    this.confirmPasswordControl = this.formBuilder
        .control(
            '',
            [Validators.required, Validators.minLength(3), checkPasswordMatch(this.passwordControl)]
        );

    this.registerForm = this.formBuilder.group({
      username: ['', [Validators.required, Validators.minLength(3)]],
      firstname: ['', [Validators.required, Validators.minLength(2)]],
      lastname: ['', [Validators.required, Validators.minLength(2)]],
      email: ['', [Validators.required, CustomValidators.email]],
      password: this.passwordControl,
      confirmPassword: this.confirmPasswordControl
    });
  }
github firebaseui / ng-bootstrap / src / auth / module / components / auth / auth.component.ts View on Github external
this.signUpFormGroup = new FormGroup({
      name: this.sigUpNameFormControl = new FormControl('',
        [
          Validators.required,
          Validators.minLength(2),
          Validators.maxLength(30),
        ]),
      email: this.sigUpEmailFormControl = new FormControl('',
        [
          Validators.required,
          Validators.pattern(EMAIL_REGEX)
        ]),
      password: this.sigUpPasswordFormControl = new FormControl('',
        [
          Validators.required,
          Validators.minLength(6),
          Validators.maxLength(25),
        ])
    });
  }
github springboot-angular2-tutorial / angular2-app / src / app / pages / +user-edit / user-edit.component.ts View on Github external
private initForm() {
    this.name = new FormControl(this.user.name, Validators.compose([
      Validators.required,
      Validators.minLength(4),
    ]));
    this.email = new FormControl(this.user.email, Validators.compose([
      Validators.required,
      Validators.pattern(EMAIL_PATTERN),
    ]));
    this.password = new FormControl('', Validators.compose([
      Validators.minLength(8),
    ]));
    this.passwordConfirmation = new FormControl('');
    this.myForm = new FormGroup({
      name: this.name,
      email: this.email,
      password: this.password,
      passwordConfirmation: this.passwordConfirmation,
    }, AppValidators.match(this.password, this.passwordConfirmation));
  }
github bkimminich / juice-shop / frontend / src / app / change-password / change-password.component.ts View on Github external
import { FormSubmitService } from '../Services/form-submit.service'
import { TranslateService } from '@ngx-translate/core'

library.add(faSave, faEdit)
dom.watch()

@Component({
  selector: 'app-change-password',
  templateUrl: './change-password.component.html',
  styleUrls: ['./change-password.component.scss']
})
export class ChangePasswordComponent {

  public passwordControl: FormControl = new FormControl('', [Validators.required])
  public newPasswordControl: FormControl = new FormControl('', [Validators.required, Validators.minLength(5), Validators.maxLength(20)])
  public repeatNewPasswordControl: FormControl = new FormControl('', [Validators.required, Validators.minLength(5), Validators.maxLength(20), matchValidator(this.newPasswordControl)])
  public error: any
  public confirmation: any

  constructor (private userService: UserService, private formSubmitService: FormSubmitService, private translate: TranslateService) { }

  ngOnInit () {
    this.formSubmitService.attachEnterKeyHandler('password-form', 'changeButton', () => this.changePassword())
  }

  changePassword () {
    this.userService.changePassword({
      current: this.passwordControl.value,
      new: this.newPasswordControl.value,
      repeat: this.repeatNewPasswordControl.value
    }).subscribe((response: any) => {
      this.error = undefined
github ng-vcl / ng-vcl / demo / app / demos / form / demo.component.ts View on Github external
import { Component, OnInit } from '@angular/core';
import { FormGroup, Validators, FormBuilder, AbstractControl, FormControl } from '@angular/forms';


function equalInputMatcher(c: AbstractControl) {

}

@Component({
  templateUrl: 'demo.component.html'
})
export class FormDemoComponent {

  form = new FormGroup({
    input1: new FormControl('', [ Validators.required, Validators.minLength(4) ]),
    input2: new FormControl('', [ ]),
    checkbox: new FormControl(true, [ ]),
    fileinput: new FormControl(null, [ ]),
    flipswitch: new FormControl(true, [ ]),
    buttonGroup: new FormControl([], [ this.validateSelection.bind(this) ]),
    dropdown: new FormControl([], [ this.validateSelection.bind(this) ]),
    radiogroup: new FormControl(null, Validators.required),
    select: new FormControl(null, Validators.required),
    slider: new FormControl(0, [ this.validateSlider.bind(this) ] ),
    textarea: new FormControl(null, Validators.required),
    tokeninput: new FormControl([], [ this.validateSelection.bind(this) ]),
  }, this.validateButtonInputs.bind(this) );

  get input1() { return this.form.get('input1'); }
  get input2() { return this.form.get('input2'); }
  get checkbox() { return this.form.get('checkbox'); }