Variable ValidationUtilsConst

ValidationUtils: {
    isBase64(base64): boolean;
    isCreditCard(number): boolean;
    isCreditCardCvv(cvv): boolean;
    isCreditCardExpiry(expiry): boolean;
    isDomain(domain): boolean;
    isEmail(email): boolean;
    isHostname(hostname): boolean;
    isEmpty(value): boolean;
    isIpAddress(ip): boolean;
    isJson(json): boolean;
    isMimeType(mimeType): boolean;
    isPassword(password, options?): boolean;
    isPhoneNumber(phone): boolean;
    isPort(port): boolean;
    isPostalCode(postalCode, country): boolean;
    isSemver(version): boolean;
    isSocialSecurityNumber(ssn, country): boolean;
    isTaxIdentificationNumber(tin, country): boolean;
    isUrl(url): boolean;
    isUsername(username, options?): boolean;
    isUuid(uuid): boolean;
} = ...

Validation utility functions for common data types and formats

Type declaration

  • isBase64:function
    • Checks if a value is a valid base64 encoded string.

      Parameters

      • base64: string

        The base64 string to validate

      Returns boolean

      True if the string is valid base64, false otherwise

      Example

      ValidationUtils.isBase64('SGVsbG8gV29ybGQ='); // Returns true
      ValidationUtils.isBase64('invalid-base64'); // Returns false
  • isCreditCard:function
    • Validates a credit card number using the Luhn algorithm.

      Parameters

      • number: string

        The credit card number to validate (can include spaces, dashes, etc.)

      Returns boolean

      True if the credit card number is valid, false otherwise

      Example

      ValidationUtils.isCreditCard('4111111111111111'); // Returns true (Visa test number)
      ValidationUtils.isCreditCard('4111-1111-1111-1111'); // Returns true (with dashes)
      ValidationUtils.isCreditCard('1234567890123456'); // Returns false (invalid)
  • isCreditCardCvv:function
    • Validates a credit card CVV (Card Verification Value).

      Parameters

      • cvv: string

        The CVV to validate (3 or 4 digits)

      Returns boolean

      True if the CVV format is valid, false otherwise

      Example

      ValidationUtils.isCreditCardCvv('123'); // Returns true
      ValidationUtils.isCreditCardCvv('1234'); // Returns true (Amex)
      ValidationUtils.isCreditCardCvv('12'); // Returns false (too short)
  • isCreditCardExpiry:function
    • Validates a credit card expiry date in MM/YY format.

      Parameters

      • expiry: string

        The expiry date to validate in MM/YY format

      Returns boolean

      True if the expiry date is valid and not in the past, false otherwise

      Example

      ValidationUtils.isCreditCardExpiry('12/25'); // Returns true (if current date is before Dec 2025)
      ValidationUtils.isCreditCardExpiry('01/20'); // Returns false (expired)
      ValidationUtils.isCreditCardExpiry('13/25'); // Returns false (invalid month)
  • isDomain:function
    • Validates a domain name format.

      Parameters

      • domain: string

        The domain name to validate

      Returns boolean

      True if the domain name format is valid, false otherwise

      Example

      ValidationUtils.isDomain('example.com'); // Returns true
      ValidationUtils.isDomain('sub.example.org'); // Returns true
      ValidationUtils.isDomain('invalid..domain'); // Returns false
  • isEmail:function
    • Validates an email address format.

      Parameters

      • email: string

        The email address to validate

      Returns boolean

      True if the email format is valid, false otherwise

      Example

      ValidationUtils.isEmail('user@example.com'); // Returns true
      ValidationUtils.isEmail('test.email+tag@domain.co.uk'); // Returns true
      ValidationUtils.isEmail('invalid-email'); // Returns false
  • isHostname:function
    • Validates a hostname format.

      Parameters

      • hostname: string

        The hostname to validate

      Returns boolean

      True if the hostname format is valid, false otherwise

      Example

      ValidationUtils.isHostname('localhost'); // Returns true
      ValidationUtils.isHostname('web-server-01'); // Returns true
      ValidationUtils.isHostname('invalid_hostname'); // Returns false
  • isEmpty:function
    • Checks if a value is empty (null, undefined, empty string, empty array, or empty object).

      Parameters

      • value: unknown

        The value to check for emptiness

      Returns boolean

      True if the value is considered empty, false otherwise

      Example

      ValidationUtils.isEmpty(null); // Returns true
      ValidationUtils.isEmpty(''); // Returns true
      ValidationUtils.isEmpty([]); // Returns true
      ValidationUtils.isEmpty({}); // Returns true
      ValidationUtils.isEmpty('hello'); // Returns false
  • isIpAddress:function
    • Validates an IP address (IPv4 or IPv6).

      Parameters

      • ip: string

        The IP address to validate

      Returns boolean

      True if the IP address format is valid, false otherwise

      Example

      ValidationUtils.isIpAddress('192.168.1.1'); // Returns true (IPv4)
      ValidationUtils.isIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // Returns true (IPv6)
      ValidationUtils.isIpAddress('256.1.1.1'); // Returns false (invalid IPv4)
  • isJson:function
    • Validates if a string is valid JSON.

      Parameters

      • json: string

        The JSON string to validate

      Returns boolean

      True if the string is valid JSON, false otherwise

      Example

      ValidationUtils.isJson('{"name": "John", "age": 30}'); // Returns true
      ValidationUtils.isJson('[1, 2, 3]'); // Returns true
      ValidationUtils.isJson('invalid json'); // Returns false
  • isMimeType:function
    • Validates a MIME type format.

      Parameters

      • mimeType: string

        The MIME type to validate

      Returns boolean

      True if the MIME type format is valid, false otherwise

      Example

      ValidationUtils.isMimeType('text/html'); // Returns true
      ValidationUtils.isMimeType('application/json'); // Returns true
      ValidationUtils.isMimeType('invalid-mime'); // Returns false
  • isPassword:function
    • Validates password strength based on configurable criteria.

      Parameters

      • password: string

        The password to validate

      • options: {
            minLength?: number;
            requireUppercase?: boolean;
            requireLowercase?: boolean;
            requireNumbers?: boolean;
            requireSpecialChars?: boolean;
        } = {}

        Password validation options

        • Optional minLength?: number

          Minimum password length (default: 8)

        • Optional requireUppercase?: boolean

          Require uppercase letters (default: true)

        • Optional requireLowercase?: boolean

          Require lowercase letters (default: true)

        • Optional requireNumbers?: boolean

          Require numbers (default: true)

        • Optional requireSpecialChars?: boolean

          Require special characters (default: true)

      Returns boolean

      True if the password meets all criteria, false otherwise

      Example

      ValidationUtils.isPassword('MyP@ssw0rd123'); // Returns true
      ValidationUtils.isPassword('weak', { minLength: 4, requireSpecialChars: false }); // Returns false
      ValidationUtils.isPassword('StrongPass123!'); // Returns true
  • isPhoneNumber:function
    • Validates a phone number format.

      Parameters

      • phone: string

        The phone number to validate

      Returns boolean

      True if the phone number format is valid, false otherwise

      Example

      ValidationUtils.isPhoneNumber('+1 (555) 123-4567'); // Returns true
      ValidationUtils.isPhoneNumber('555-123-4567'); // Returns true
      ValidationUtils.isPhoneNumber('123'); // Returns false (too short)
  • isPort:function
    • Checks if a value is a valid port number

      Parameters

      • port: number

        Port number to validate

      Returns boolean

      True if valid, false otherwise

  • isPostalCode:function
    • Checks if a value is a valid postal code

      Parameters

      • postalCode: string

        Postal code to validate

      • country: string

        Country code (ISO 3166-1 alpha-2)

      Returns boolean

      True if valid, false otherwise

  • isSemver:function
    • Checks if a value is a valid semver version

      Parameters

      • version: string

        Version string to validate

      Returns boolean

      True if valid, false otherwise

  • isSocialSecurityNumber:function
    • Checks if a value is a valid social security number

      Parameters

      • ssn: string

        Social security number to validate

      • country: string

        Country code (ISO 3166-1 alpha-2)

      Returns boolean

      True if valid, false otherwise

  • isTaxIdentificationNumber:function
    • Checks if a value is a valid tax identification number

      Parameters

      • tin: string

        Tax identification number to validate

      • country: string

        Country code (ISO 3166-1 alpha-2)

      Returns boolean

      True if valid, false otherwise

  • isUrl:function
    • Checks if a value is a valid URL

      Parameters

      • url: string

        URL to validate

      Returns boolean

      True if valid, false otherwise

  • isUsername:function
    • Checks if a value is a valid username

      Parameters

      • username: string

        Username to validate

      • options: {
            minLength?: number;
            maxLength?: number;
            allowSpecialChars?: boolean;
        } = {}

        Username validation options

        • Optional minLength?: number
        • Optional maxLength?: number
        • Optional allowSpecialChars?: boolean

      Returns boolean

      True if valid, false otherwise

  • isUuid:function
    • Checks if a value is a valid UUID

      Parameters

      • uuid: string

        UUID to validate

      Returns boolean

      True if valid, false otherwise