logo
search icon
Close
FrameworkLibrariesCommunityDocumentation
Chapters
Deepkit Runtime Types // Examples

Validate username and email

Back to all Deepkit Runtime Types examples
import { Email, MaxLength, MinLength, Pattern, validate } from '@deepkit/type';

type Username = string & MinLength<3> & MaxLength<20> & Pattern<'^[a-zA-Z0-9]+$'>;

class User {
    email: Email = '';
    username: Username = '';
}

const errors = validate<User>({ email: 'peter@example.com', username: 'pet' });
console.log(errors); // [{ path: 'username', message: '...' }]
IntroductionExamplesJoin Discord
App
Getting startedExamplesArguments & FlagsDependency InjectionModulesServicesEventsLoggerConfiguration
Framework
Getting startedExamplesDatabaseTestingDeploymentPublic Assets
Runtime Types
IntroductionGetting startedExamplesType AnnotationsReflectionSerializationValidationExtendCustom serializerExternal TypesBytecode
Dependency Injection
IntroductionGetting startedExamplesProvidersInjectionConfigurationScopes
Filesystem
Getting startedExamplesAppLocalMemoryAWS S3FTPsFTP (SSH)Google Storage
Broker
Getting startedCacheMessage BusMessage QueueAtomic LocksKey Value
HTTP
IntroductionGetting startedExamplesInput & OutputViewsDependency InjectionEventsMiddlewareSecurity
RPC
IntroductionGetting startedExamplesDependency InjectionSecurityErrorsTransport
Database ORM
IntroductionGetting startedExamplesEntitySessionQueryTransactionInheritanceRelationsEventsMigrationsORM BrowserRaw AccessSeedingComposite primary key
Plugins
Soft-Delete