rgex
Version:
A powerful, chainable regex builder platform with comprehensive validation utilities
125 lines • 7.09 kB
TypeScript
/**
* @fileoverview RGex Pattern Constants - Pre-defined regex patterns for common use cases
* @module Constants
* @category Constants
* @group Pattern Definitions
* @author duongnguyen321 - https://duonguyen.site
*/
import type { HumanTextPattern } from '../../types/index.js';
export declare const REGEX_PATTERNS: {
readonly EMAIL: "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
readonly URL: "^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$";
readonly PHONE: "^\\+?[1-9]\\d{4,14}$";
readonly DATE: "^\\d{4}-\\d{2}-\\d{2}$";
readonly TIME: "^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$";
readonly INTEGER: "^-?\\d+$";
readonly DECIMAL: "^-?\\d+(\\.\\d+)?$";
readonly POSITIVE_INTEGER: "^[1-9]\\d*$";
readonly POSITIVE_DECIMAL: "^([1-9]\\d*|0)(\\.\\d+)?$";
readonly UUID: "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$";
readonly MONGO_ID: "^[0-9a-fA-F]{24}$";
readonly IPV4: "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
readonly IPV6: "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))$";
readonly DOMAIN: "^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?.)+[a-zA-Z]{2,}$";
readonly MAC_ADDRESS: "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
readonly HEX_COLOR: "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$";
readonly SLUG: "^[a-z0-9]+(?:-[a-z0-9]+)*$";
readonly USERNAME: "^[a-zA-Z0-9_]{3,20}$";
readonly FILE_EXTENSION: "^.*\\.[a-zA-Z0-9]{1,10}$";
readonly IMAGE_FILE: "^.*\\.(jpg|jpeg|png|gif|bmp|svg|webp|ico)$";
readonly DOCUMENT_FILE: "^.*\\.(pdf|doc|docx|txt|rtf|odt)$";
readonly TIMESTAMP: "^[0-9]{10,13}$";
readonly ISO_DATETIME: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z?$";
readonly CREDIT_CARD: "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3[0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$";
readonly VISA_CARD: "^4[0-9]{12}(?:[0-9]{3})?$";
readonly MASTERCARD: "^5[1-5][0-9]{14}$";
readonly AMEX: "^3[47][0-9]{13}$";
readonly PASSWORD: "^.{6,}$";
readonly STRONG_PASSWORD: "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]).{8,}$";
readonly DIGITS_ONLY: "^\\d+$";
readonly LETTERS_ONLY: "^[a-zA-Z]+$";
readonly ALPHANUMERIC: "^[a-zA-Z0-9]+$";
readonly NO_SPACES: "^\\S+$";
readonly TEXT: "^[a-zA-Z0-9\\s.,!?;:'\"-]+$";
readonly US_ZIP_CODE: "^\\d{5}(-\\d{4})?$";
readonly CANADIAN_POSTAL_CODE: "^[A-Za-z]\\d[A-Za-z][ -]?\\d[A-Za-z]\\d$";
readonly UK_POSTCODE: "^[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}$";
readonly GERMAN_POSTCODE: "^\\d{5}$";
readonly FRENCH_POSTCODE: "^\\d{5}$";
readonly SSN: "^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$";
readonly BASE64: "^[A-Za-z0-9+/]*={0,2}$";
readonly BITCOIN_ADDRESS: "^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$";
readonly ETHEREUM_ADDRESS: "^0x[a-fA-F0-9]{40}$";
readonly IBAN: "^[A-Z]{2}[0-9]{2}[A-Z0-9]{4,30}$";
readonly SWIFT_CODE: "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$";
readonly ISBN_10: "^(?:\\d{9}[\\dX]|\\d{10})$";
readonly ISBN_13: "^97[89]\\d{10}$";
readonly SEMVER: "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$";
readonly JWT_TOKEN: "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_.+/=]*$";
readonly GIT_COMMIT: "^[a-f0-9]{7,40}$";
readonly GITHUB_USERNAME: "^[a-z\\d](?:[a-z\\d]|-(?=[a-z\\d])){0,38}$";
readonly TWITTER_HANDLE: "^@?(\\w){1,15}$";
readonly DISCORD_ID: "^\\d{17,19}$";
readonly SLACK_USER_ID: "^U[A-Z0-9]{8,10}$";
readonly YOUTUBE_VIDEO_ID: "^[a-zA-Z0-9_-]{11}$";
readonly AWS_S3_BUCKET: "^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$";
readonly DOCKER_IMAGE: "^[a-z0-9]+(?:[._-][a-z0-9]+)*(?:\\/[a-z0-9]+(?:[._-][a-z0-9]+)*)*(?::[a-zA-Z0-9._-]+)?$";
readonly K8S_RESOURCE_NAME: "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$";
readonly NPM_PACKAGE: "^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$";
readonly E164_PHONE: "^\\+[1-9]\\d{1,14}$";
readonly LINKEDIN_PROFILE: "^https:\\/\\/(www\\.)?linkedin\\.com\\/in\\/[a-zA-Z0-9-]+\\/?$";
readonly GOOGLE_DRIVE_ID: "^[a-zA-Z0-9-_]{25,}$";
readonly FIREBASE_PROJECT_ID: "^[a-z0-9-]{6,30}$";
readonly AZURE_RESOURCE_GROUP: "^[a-zA-Z0-9._()-]{1,90}$";
};
export declare const HUMAN_PATTERNS: Record<string, HumanTextPattern>;
export declare const PATTERN_KEYWORDS: Record<string, string[]>;
export declare const COMMON_PASSWORDS: string[];
export declare const SPECIAL_CHARS = "!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?";
export declare const SYMBOLS = "[^\\w\\s]";
export declare const UNICODE_RANGE = "[^\\x00-\\x7F]";
/**
* Creates a regex pattern that matches the start of a string.
* @param text - The text to match at the beginning.
* @returns A regex pattern string.
*/
export declare const STARTS_WITH: (text: string) => string;
/**
* Creates a regex pattern that matches the end of a string.
* @param text - The text to match at the end.
* @returns A regex pattern string.
*/
export declare const ENDS_WITH: (text: string) => string;
/**
* Creates a regex pattern that matches if a string contains the given text.
* @param text - The text to search for within the string.
* @returns A regex pattern string.
*/
export declare const CONTAINS: (text: string) => string;
/**
* Creates a regex pattern for an exact length.
* @param n - The exact number of characters.
* @returns A regex pattern string.
*/
export declare const EXACT_LENGTH: (n: number) => string;
/**
* Creates a regex pattern for a minimum length.
* @param n - The minimum number of characters.
* @returns A regex pattern string.
*/
export declare const MIN_LENGTH: (n: number) => string;
/**
* Creates a regex pattern for a maximum length.
* @param n - The maximum number of characters.
*
* @returns A regex pattern string.
*/
export declare const MAX_LENGTH: (n: number) => string;
/**
* Creates a regex pattern for a length within a given range.
* @param min - The minimum number of characters.
* @param max - The maximum number of characters.
* @returns A regex pattern string.
*/
export declare const BETWEEN_LENGTH: (min: number, max: number) => string;
//# sourceMappingURL=patterns.d.ts.map