JS Utils Kit
    Preparing search index...

    Function isEmail

    • Checks whether a given string is a valid email address.

      Parameters

      • value: string

        The string to validate as an email address

      • regex: RegExp = EMAIL_REGEX_PRESETS.strict

        Custom regular expression to use for validation against provided value.

        Defaults to EMAIL_REGEX_PRESETS.strict, which is designed to cover common email formats while excluding complex edge cases.

      Returns boolean

      true if the string is a valid email; otherwise, false.

      This function validates the input using a practical regular expression (EMAIL_REGEX_PRESETS.strict) that supports most common email formats while intentionally ignoring edge cases defined by full RFC 5322.

      Validation is fully delegated to the provided regex, which ensures:

      • A valid local part and domain structure
      • Presence of a single @ symbol
      • Proper domain formatting (e.g., contains a dot and valid labels)

      Limits enforced:

      • Total email length: ≤ 254 characters

      Throws if value is not a string.

      isEmail('user@example.com'); // true
      isEmail('first.last@college.university.in'); // true
      isEmail('invalid-email'); // false
      isEmail('name@domain'); // false
      const ONLY_EXAMPLE_DOMAIN = /^[^@]+@example\.com$/;
      isEmail('user@example.com', ONLY_EXAMPLE_DOMAIN); // true
      isEmail('user@gmail.com', ONLY_EXAMPLE_DOMAIN); // false

      EMAIL_REGEX_PRESETS.strict for the default regular expression used in validation.