Skip to content

v2.4.0

Choose a tag to compare

@milwad-dev milwad-dev released this 12 Nov 11:34
· 13 commits to 1.x since this release

What's New

New rules

  • ValidEthereumAddress: validates Ethereum addresses, including the EIP-55 checksum. Mixed-case addresses must have a valid checksum; all-lowercase or all-uppercase addresses are accepted unless you use strict mode.
    new ValidEthereumAddress()      // checksum checked when mixed-case
    new ValidEthereumAddress(true)  // checksum required
  • ValidCountryCode: validates ISO 3166-1 country codes against all 249 officially assigned codes. Accepts alpha-2 (US) by default, or alpha-3 (USA). Case-insensitive.
    new ValidCountryCode()                          // US
    new ValidCountryCode(ValidCountryCode::ALPHA3)  // USA
  • ValidMongoObjectId: validates MongoDB ObjectIds (24 hex characters). Also accepts MongoDB\BSON\ObjectId instances.
  • ValidCssColor: validates any CSS color: hex (3/4/6/8 digits), rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() and all named colors. Supports both comma and space syntax, checks value ranges, and can be limited to specific formats.
    new ValidCssColor()                                          // any format
    new ValidCssColor([ValidCssColor::HEX, ValidCssColor::RGB])  // hex and rgb only

All new rules work with using_container as string rules (ValidEthereumAddress:strict, ValidCountryCode:alpha3, ValidCssColor:hex,rgb) and include error messages in all 25 supported languages.

Fixes

  • Trailing newlines are now rejected. In PHP regex, $ also matches before a final newline, so a value like "milwad-dev\n" passed ValidSlug, and the same was true for almost every rule and country phone/landline validator. All whole-string patterns now use the D modifier.
  • ValidUlid now matches the whole value. It previously accepted any string that contained a ULID, such as prefix-01ARZ3NDEKTSV4RRFFQ69G5FAV-suffix.

⚠️ Behavior changes

The fixes above make validation stricter. If your app passed values with a trailing newline (for example, unsanitized textarea input or values read from files), they will now fail validation. Trim the input first, for example with Laravel's TrimStrings middleware, which is enabled by default.

Full Changelog: v2.3.0...v2.4.0