Skip to content

Instantly share code, notes, and snippets.

@codewithleader
Created May 7, 2023 04:17
Show Gist options
  • Save codewithleader/14f8f85c1938a7fa66f01350b05a515e to your computer and use it in GitHub Desktop.
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
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