Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created September 2, 2018 15:30
Show Gist options
  • Save larkintuckerllc/f2c0203d7998f4bb6cd48898b1869315 to your computer and use it in GitHub Desktop.
Save larkintuckerllc/f2c0203d7998f4bb6cd48898b1869315 to your computer and use it in GitHub Desktop.
TypeORM 15
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