Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
ng2-validators
Advanced tools
An implementation of various angular validators for Angular 2.
List of validators
The rules are from https://github.com/vt-middleware/passay
The password validators are:
npm install ng2-validators --save
needs: ReactiveFormsModule
@import {PasswordValidators} from 'ng2-validators'
...
password: Control = new Control('', Validators.compose([
PasswordValidators.repeatCharacterRegexRule(4),
PasswordValidators.whitespaceRule(),
PasswordValidators.alphabeticalCharacterRule(1);
PasswordValidators.digitCharacterRule(1);
PasswordValidators.lowercaseCharacterRule(1);
PasswordValidators.uppercaseCharacterRule(1);
PasswordValidators.allowedCharacterRule(['a', 'b']);
]));
@import {PasswordValidators} from 'ng2-validators'
...
let password: FormControl = new FormControl('testPassword');
let confirmPassword: FormControl = new FormControl('testPassword');
let form = new FormGroup({
'newPassword': password,
'confirmPassword': confirmPassword
}, PasswordValidators.mismatchedPasswords()
);
@import {PasswordValidators} from 'ng2-validators'
...
let password: FormControl = new FormControl('testPassword');
let confirmPassword: FormControl = new FormControl('testPassword');
let form = new FormGroup({
'testName': password,
'testName2': confirmPassword
}, PasswordValidators.mismatchedPasswords('testName', 'testName2' )
);
@import {EmailValidators} from 'ng2-validators'
...
email: Control = new Control('', EmailValidators.normal());
email2: Control = new Control('', EmailValidators.simple());
@import {UniversalValidators} from 'ng2-validators'
...
control: Control = new Control('', UniversalValidators.noWhitespace());
control: Control = new Control('', UniversalValidators.isNumber());
control: Control = new Control('', UniversalValidators.isInRange(2, 5));
control: Control = new Control('', UniversalValidators.minLength(2));
control: Control = new Control('', UniversalValidators.maxLength(7));
control: Control = new Control('', UniversalValidators.min(2));
control: Control = new Control('', UniversalValidators.max(2));
@import {CreditCardValidators} from 'ng2-validators'
...
control: Control = new Control('', UniversalValidators.isCreditCard());
control: Control = new Control('', UniversalValidators.americanExpress());
control: Control = new Control('', UniversalValidators.dinersclub());
control: Control = new Control('', UniversalValidators.discover());
control: Control = new Control('', UniversalValidators.jcb());
control: Control = new Control('', UniversalValidators.maestro());
control: Control = new Control('', UniversalValidators.mastercard());
control: Control = new Control('', UniversalValidators.visa());
@import {PhoneValidators} from 'ng2-validators'
...
countryCode: Control = new Control('', PhoneValidators.isValidRegionCode());
phone: Control = new Control('', PhoneValidators.isPhoneNumber());
phone2: Control = new Control('', PhoneValidators.isPossibleNumberWithReason());
needs FormsModule and ValidatorsModule
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { ValidatorsModule } from 'ng2-validators'
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, FormsModule, ValidatorsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
<form>
<input type="password" [(ngModel)]="model.password" name="password" #formControl="ngModel" password>
<span *ngIf="formControl.errors?.repeatCharacterRegexRule">Password contains repeating characters</span>
<span *ngIf="formControl.errors?.digitCharacterRule">Password should contain at least on digit</span>
<span *ngIf="formControl.errors?.alphabeticalCharacterRule">Password should contain at least on alphabetical character</span>
<span *ngIf="formControl.errors?.lowercaseCharacterRule">Password should contain at least on lowercase character</span>
<span *ngIf="formControl.errors?.uppercaseCharacterRule">Password should contain at least on uppercase character</span>
</form>
// Override values
<input type="password" [(ngModel)]="model.password" name="password" #formControl="ngModel"
password
[repeatCharacter]="2"
[alphabeticalCharacter]="2"
[digitCharacter]="2"
[lowercaseCharacter]="2"
[uppercaseCharacter]="2"
>
<form>
<input type="text" [(ngModel)]="model.creditcard" name="creditcard" #formControl="ngModel" creditCard>
<span *ngIf="formControl.errors?.creditcard">Is not a creditcard</span>
</form>
// Override values
// Test only for a specific creditcard
<input type="text" [(ngModel)]="model.creditcard" name="creditcard" #formControl="ngModel" [creditCard]="all|americanExpress|dinersclub|discover|jcb|maestro|mastercard|visa">
<form>
<input type="text" [(ngModel)]="model.email" name="email" #formControl="ngModel" email>
<span *ngIf="formControl.errors?.normalEmailRule">Is not a email</span>
</form>
<form>
<input type="text" [(ngModel)]="model.phone" name="phone" #formControl="ngModel" phone="US">
<span *ngIf="formControl.errors?.noValidRegionCode">Is not a countryCode</span>
<span *ngIf="formControl.errors?.noPhoneNumber">Is not a phone number</span>
</form>
<form>
<input type="text" [(ngModel)]="model.phone" name="phone" #formControl="ngModel" possiblePhone="US">
<span *ngIf="formControl.errors?.noValidRegionCode">Is not a countryCode</span>
<span *ngIf="formControl.errors?.phoneNumberTooLong">Phone number is to long</span>
<span *ngIf="formControl.errors?.phoneNumberTooShort">Phone number is to short</span>
<span *ngIf="formControl.errors?.noPhoneNumber">Is not a phone number</span>
</form>
<form>
<input type="text" [(ngModel)]="model.countryCode" name="countryCode" #formControl="ngModel" countryCode>
<span *ngIf="formControl.errors?.noValidRegionCode">Is not a countryCode</span>
</form>
<form>
<input type="text" [(ngModel)]="model.firstname" name="firstname" #formControl="ngModel" noWhitespace>
<span *ngIf="formControl.errors?.noWhitespaceRequired">Should not contain a whitespace</span>
</form>
<form>
<input type="number" [(ngModel)]="model.amount" name="amount" #formControl="ngModel" isNumber>
<span *ngIf="formControl.errors?.numberRequired">Needs to be a number</span>
</form>
<form>
<input type="number" [(ngModel)]="model.amount" name="amount" #formControl="ngModel" isInRange [minValue]="2" [maxValue]="4">
<span *ngIf="formControl.errors?.numberRequired">Needs to be a number</span>
<span *ngIf="formControl.errors?.rangeValueToSmall">Number to small</span>
<span *ngIf="formControl.errors?.rangeValueToBig">Number to big</span>
</form>
<form>
<input type="number" [(ngModel)]="model.amount" name="amount" #formControl="ngModel" [min]="2">
<span *ngIf="formControl.errors?.numberRequired">Needs to be a number</span>
<span *ngIf="formControl.errors?.min">Number to small</span>
</form>
<form>
<input type="number" [(ngModel)]="model.amount" name="amount" #formControl="ngModel" [max]="2">
<span *ngIf="formControl.errors?.numberRequired">Needs to be a number</span>
<span *ngIf="formControl.errors?.max">Number to small</span>
</form>
##Todo
Get the complete changelog here: https://github.com/Nightapes/ng2-validators/releases
FAQs
An implementation of angular validators for Angular 2
The npm package ng2-validators receives a total of 65 weekly downloads. As such, ng2-validators popularity was classified as not popular.
We found that ng2-validators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.