Notes
Notes - notes.io |
import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
@Directive({
selector: '[containsNumber]',
providers: [
{
provide: NG_VALIDATORS,
useExisting: ContainsNumberDirective,
multi: true
}
]
})
export class ContainsNumberDirective implements Validator {
private readonly regex = /d/;
validate(control: AbstractControl): ValidationErrors | null {
const value = control.value;
if (value == null || value === '') {
return null; // Let required handle empty input
}
return this.regex.test(value) ? null : { missingNumber: true };
}
}import { Directive } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
@Directive({
selector: '[lowercaseValidation]',
providers: [
{
provide: NG_VALIDATORS,
useExisting: LowercaseValidationDirective,
multi: true
}
]
})
export class LowercaseValidationDirective implements Validator {
private readonly regex = /[a-z]/;
validate(control: AbstractControl): ValidationErrors | null {
const value = control.value;
if (value == null || value === '') {
return null; // let required validator handle empty values
}
return this.regex.test(value) ? null : { validLowercase: true };
}
}import { Directive } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
@Directive({
selector: '[uppercaseValidation]',
providers: [
{
provide: NG_VALIDATORS,
useExisting: UppercaseValidationDirective,
multi: true
}
]
})
export class UppercaseValidationDirective implements Validator {
private readonly regex = /[A-Z]/;
validate(control: AbstractControl): ValidationErrors | null {
const value = control.value;
if (value == null || value === '') {
return null; // let required validator handle empty values
}
return this.regex.test(value) ? null : { validUppercase: true };
}
}import { Directive } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
@Directive({
selector: '[specialCharPasswordValidation]',
providers: [
{
provide: NG_VALIDATORS,
useExisting: SpecialCharPasswordValidationDirective,
multi: true
}
]
})
export class SpecialCharPasswordValidationDirective implements Validator {
private readonly allowedPattern = /[!@#$%^&.~*()+-{};':<>/?-]/;
private readonly disallowedPattern = /[],"_/; // Possibly malformed, but kept as in original
private readonly cleanRegex = /[a-zA-Z0-9àðäèéëîïõœüüüÿçÄÄÄÈÉLEÎÏÖGUÜOYC]/g;
validate(control: AbstractControl): ValidationErrors | null {
const value = control.value;
if (!value) {
return null; // let required handle empty values
}
// Simulates angular.copy and cleanup logic
const cleaned = value.replace(this.cleanRegex, '');
const hasValidSpecialChar = this.allowedPattern.test(cleaned);
const hasDisallowedChar = this.disallowedPattern.test(cleaned);
return hasValidSpecialChar && !hasDisallowedChar
? null
: { validSpecialCharacter: true };
}
}import { Directive } from '@angular/core';
import { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
@Directive({
selector: '[passwordLengthValidation]',
providers: [
{
provide: NG_VALIDATORS,
useExisting: PasswordLengthValidationDirective,
multi: true
}
]
})
export class PasswordLengthValidationDirective implements Validator {
validate(control: AbstractControl): ValidationErrors | null {
const value = control.value;
if (!value) {
return null; // let required handle empty values
}
return value.length >= 8 ? null : { validPasswordLength: true };
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
