npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-validate

v0.0.21

Published

An implementation of various angular validators for Angular 2+.

Downloads

16

Readme

ngx-validator

An implementation of various angular validators for Angular 2+.

Currently support data-driven form only.

List of validators

  1. isNumber(Allow only number or + or - or .)
  2. strongPassword
  3. matchPassword
  4. requiredIfInputHasValue
  5. numberLetterOnly
  6. numberLetterSpaceOnly
  7. noBlank
  8. asyncDuplicate

Install

npm install ngx-validate

Example

https://angular-ngx-validate-example.stackblitz.io/

#Code

Html

<!-- main app container -->
<div class="jumbotron">
  <div class="container">
    <div class="row">
      <div class="col-md-6 offset-md-3">
        <h3>Angular Reactive Form with NgxValidate</h3>
        <form [formGroup]="myForm" novalidate (ngSubmit)="onSubmit(myForm)">
          <div class="form-group">
            <label>Name</label>
            <input type="text"
                   formControlName="name"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['name'].valid && myForm.controls['name'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('name')"></validation-error>
          </div>

          <div class="form-group">
            <label>Required When Name Has Value</label>
            <input type="text"
                   formControlName="requiredWhenNameHasValue"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['requiredWhenNameHasValue'].valid && myForm.controls['requiredWhenNameHasValue'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('requiredWhenNameHasValue')"></validation-error>
          </div>

          <div class="form-group">
            <label>Async Validate</label>
            <input type="text"
                   formControlName="asyncValidate"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['asyncValidate'].valid && myForm.controls['asyncValidate'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('asyncValidate')"></validation-error>
          </div>

          <div class="form-group">
            <label>Number</label>
            <input type="text"
                   formControlName="number"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['number'].valid && myForm.controls['number'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('number')"></validation-error>
          </div>

          <div class="form-group">
            <label>Number or Letter Only</label>
            <input type="text"
                   formControlName="numberLetterOnly"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['numberLetterOnly'].valid && myForm.controls['numberLetterOnly'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('numberLetterOnly')"></validation-error>
          </div>

          <div class="form-group">
            <label>Password</label>
            <p style="font-size: small">should contain number and uppercase letter and lower case letter and length should more than 7</p>
            <input type="text"
                   formControlName="password"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['password'].valid && myForm.controls['password'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('password')"></validation-error>
          </div>


          <div class="form-group">
            <label>Repeat Password</label>
            <input type="text"
                   formControlName="repeatPassword"
                   class="form-control"
                   [ngClass]="{'bg-danger': (!myForm.controls['repeatPassword'].valid && myForm.controls['repeatPassword'].touched)}"/>
            <validation-error [errorClass]="'text-danger'" [control]="myForm.get('repeatPassword')"></validation-error>
          </div>

          <div class="form-group">
            <button class="btn btn-primary">Submit</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

Component:

  class AppComponent {
    public myForm: FormGroup;
  
    constructor(private formBuiler: FormBuilder,
                private http: HttpClient,
                private ngxValidateService: NgxValidateService) {
      this.initFormControl();
    }
  
    initFormControl() {
      this.myForm = this.formBuiler.group({
        name: new FormControl(null, {validators: [Validators.required]}
        ),
        asyncValidate: new FormControl(null, {
            validators: [],
            asyncValidators: [NgxValidators.asyncDuplicate(
              'http://dummy.restapiexample.com/api/v1/employee/1', this.http, true
            )]
          }
        ),
        requiredWhenNameHasValue: new FormControl(null, {
            validators: [NgxValidators.requiredIfInputHasValue('name')]
          }
        ),
        number: new FormControl('abcd',
          {validators: [Validators.required, NgxValidators.isNumber]}
        ),
        numberLetterOnly: new FormControl(null,
          {validators: [NgxValidators.numberLetterOnly]}
        ),
        password: new FormControl(null,
          {
            validators: [
              Validators.required,
              NgxValidators.strongPassword
            ]
          }),
        repeatPassword: new FormControl(null,
          {validators: NgxValidators.matchPassword('password')})
      });
    }
  
    onSubmit({value, valid}: { value: any, valid: boolean }) {
      if (valid) {
        console.log(value);
        alert(JSON.stringify(value));
      } else {
        console.log(this.myForm);
        Object.keys(this.myForm.controls).forEach(key => {
          this.ngxValidateService.validateAllFormFields(this.myForm);
        });
      }
    }