Created
May 7, 2023 04:17
-
-
Save codewithleader/14f8f85c1938a7fa66f01350b05a515e to your computer and use it in GitHub Desktop.
Verificar Id de Firebase - Expresion Regular REGEX para comprobar si un ID es un FirebaseId válido
This file contains 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 { ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator'; | |
const FIRESTORE_ID_REGEX = /^[a-zA-Z0-9_-]{20}$/; | |
@ValidatorConstraint({ name: 'isFirestoreId', async: false }) | |
export class IsFirestoreId implements ValidatorConstraintInterface { | |
validate(id: string) { | |
return FIRESTORE_ID_REGEX.test(id); | |
} | |
defaultMessage() { | |
return 'Invalid Firestore document ID'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment