Created
September 2, 2018 15:30
-
-
Save larkintuckerllc/f2c0203d7998f4bb6cd48898b1869315 to your computer and use it in GitHub Desktop.
TypeORM 15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator'; | |
const REGEX = /^[A-Z]/; | |
const MESSAGE = 'Text ($value) is does not start with capital letter!'; | |
@ValidatorConstraint({ name: 'capitalLetter', async: false }) | |
export default class CapitalLetterValidator implements ValidatorConstraintInterface { | |
public validate(text: string) { | |
return REGEX.test(text); | |
} | |
public defaultMessage(args: ValidationArguments) { | |
return MESSAGE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment