GithubHelp home page GithubHelp logo

ng-validators's Introduction

@moebius/ng-validators

npm version

This repository contains a collection of useful Angular input validators, some of which could also be used independently.

Installation

npm i -S @moebius/ng-validators

Usage

import { birthDateValidator } from '@moebius/ng-validators';

this.form = this.formBuilder.group({
  birthDate: [null, [
    birthDateValidator({
      minYearsOld: 18,
      maxYearsOld: 60,
    }),
  ]],
});

Provided validators

Password

passwordValidator(options: PasswordValidatorOptions)

Checks if value is a correct password.

  • options.minLength: number
  • options.maxLength: number
  • options.requireLetters: boolean
  • options.requireLowerCaseLetters: boolean
  • options.requireUpperCaseLetters: boolean
  • options.requireNumbers: boolean
  • options.requireSpecialCharacters: boolean

Match Other

matchOtherValidator(otherControlName: string)

Checks if value equals to the value in another input. Also, watched for events from another input to re-validate when necessary.

  • otherControlName: string — specify the name of another form control, both controls must be in the same control group

Skype Name

skypeNameValidator()

Checks if value contains valid skype login name.

Birth Date

birthDateValidator(options: BirthDateValidatorOptions)

Validates the specified date of birth relative to the current date.

The date could be specified as native Date object, moment.js object or js-joda LocalDate.

  • options.minYearsOld: number — minimal years old, e.g. 18 (legal age)
  • options.maxYearsOld: number — maximum years old, e.g. 60 (pension age)

Support

If this library is useful to you, please add a star on GitHub repository.

Thank you!

License

The MIT License (MIT)

Copyright (c) 2017—2019, MOEBIUS FOUNDATION, Slava Fomin II

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ng-validators's People

Contributors

slavafomin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ng-validators's Issues

Feature ideas

Hey Moebius, Awesome repo here. I've bene on the hunt for a really well written and documented collection of custom validators for Angular 2+. Are you interested in growing this repo? I would be willing to commit all my custom validators if so.

I'm looking for alpha characters only and numeric characters only validators for name fields.

Something like this for alpha only:

import { FormControl } from '@angular/forms';

export class AlphaOnlyValidator {
    static invalidAlphaOnly(control: FormControl): { [key: string]: boolean } {
        if (control.value.length && !control.value.match(/^[a-z]+$/i)) {
            return { invalidAlphaNumeric: true };
        }
        return null;
    }
}

Cause Angular AoT build errors

Hi,

This plugin cause an "AoT build failed" error when compiling a project in production mode.
Output of error :

`typescript error:
Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function,
resolving symbol Injectable in path_to_project/node_modules/@moebius/ng-validators/node_modules/@angular/core/core.d.ts,
resolving symbol ɵi in path_to_project/node_modules/@moebius/ng-validators/node_modules/@angular/forms/forms.d.ts,
resolving symbol ɵi in path_to_project/node_modules/@moebius/ng-validators/node_modules/@angular/forms/forms.d.ts

Error: The Angular AoT build failed.`

Your plugin seems to not been compatible with Angular AoT,

Thank you

Expected validator to return Promise or Observable.

I am getting this error on Angular 4+

Expected validator to return Promise or Observable.

Using like this:
this.newPasswordForm = this.formBuilder.group({ password: ['', [Validators.required, Validators.minLength(6)]], password2: ['', [Validators.required, matchOtherValidator("password")]] });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.