Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Feat: Add color_hex validation rule #49056

Merged
merged 3 commits into from
Nov 20, 2023
Merged

[10.x] Feat: Add color_hex validation rule #49056

merged 3 commits into from
Nov 20, 2023

Conversation

nikopeikrishvili
Copy link
Contributor

@nikopeikrishvili nikopeikrishvili commented Nov 20, 2023

This PR adds a hex color validation rule to check that an attribute is a valid HEX color.
There are a couple of rules for HEX color to be valid:

Standard 6-Digit Hex Codes:
Format: #RRGGBB
Each pair of characters (RR, GG, BB) represents the intensity of red, green, and blue colors, respectively.
Each pair is written in hexadecimal format, ranging from 00 to FF.
Example: #FF0000 represents pure red, with maximum intensity of red and no green or blue.

Short 3-Digit Hex Codes:
Format: #RGB
A shorthand version where each character represents red, green, and blue, but with less precision.
Each character is in hexadecimal, ranging from 0 to F.
Example: #F00 is equivalent to #FF0000, both representing pure red.

Error message in case of error:
Screenshot 2023-11-20 at 21 30 06

@taylorotwell taylorotwell merged commit 85fcda7 into laravel:10.x Nov 20, 2023
20 checks passed
@apih
Copy link
Contributor

apih commented Nov 21, 2023

@nikopeikrishvili @taylorotwell Can this be extended to cover alpha channel? I have the same name of rule defined in my apps, and currently this built-in version will fail the input from my users, since the values will contain alpha channel as well.

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color

@ahinkle
Copy link
Contributor

ahinkle commented Nov 21, 2023

Hey @apih,

I had a similar case -- which this PR will eliminate my custom rule. I contributed alpha channel support which was recently merged:

#49069

@apih
Copy link
Contributor

apih commented Nov 21, 2023

Hey @ahinkle, thanks for your PR. I noticed that your PR allowed 5 digits value to pass, which is not valid, so I opened a PR myself to fix that.

#49070

@ahinkle
Copy link
Contributor

ahinkle commented Nov 21, 2023

Hey thanks! Good catch.

renovate bot referenced this pull request in RadioRoster/backend Nov 24, 2023
[![Mend Renovate logo
banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [laravel/framework](https://laravel.com)
([source](https://github.com/laravel/framework)) | `10.30.1` ->
`10.33.0` |
[![age](https://developer.mend.io/api/mc/badges/age/packagist/laravel%2fframework/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/laravel%2fframework/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/laravel%2fframework/10.30.1/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/laravel%2fframework/10.30.1/10.33.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>laravel/framework (laravel/framework)</summary>

###
[`v10.33.0`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10330---2023-11-21)

[Compare
Source](https://github.com/laravel/framework/compare/v10.32.1...v10.33.0)

- \[10.x] Fix wrong parameter passing and add these rules to dependent
rules by [@&#8203;kayw-geek](https://github.com/kayw-geek) in
[https://github.com/laravel/framework/pull/49008](https://github.com/laravel/framework/pull/49008)
- \[10.x] Make Validator::getValue() public by
[@&#8203;shinsenter](https://github.com/shinsenter) in
[https://github.com/laravel/framework/pull/49007](https://github.com/laravel/framework/pull/49007)
- \[10.x] Custom messages for `Password` validation rule by
[@&#8203;rcknr](https://github.com/rcknr) in
[https://github.com/laravel/framework/pull/48928](https://github.com/laravel/framework/pull/48928)
- \[10.x] Round milliseconds in database seeder console output runtime
by [@&#8203;SjorsO](https://github.com/SjorsO) in
[https://github.com/laravel/framework/pull/49014](https://github.com/laravel/framework/pull/49014)
- \[10.x] Add a `Number` utility class by
[@&#8203;caendesilva](https://github.com/caendesilva) in
[https://github.com/laravel/framework/pull/48845](https://github.com/laravel/framework/pull/48845)
- \[10.x] Fix the replace() method in DefaultService class by
[@&#8203;jonagoldman](https://github.com/jonagoldman) in
[https://github.com/laravel/framework/pull/49022](https://github.com/laravel/framework/pull/49022)
- \[10.x] Pass the property $validator as a parameter to the $callback
Closure by [@&#8203;shinsenter](https://github.com/shinsenter) in
[https://github.com/laravel/framework/pull/49015](https://github.com/laravel/framework/pull/49015)
- \[10.x] Fix Cache DatabaseStore::add() error occur on Postgres within
transaction by [@&#8203;xdevor](https://github.com/xdevor) in
[https://github.com/laravel/framework/pull/49025](https://github.com/laravel/framework/pull/49025)
- \[10.x] Support asserting against chained batches by
[@&#8203;taylorotwell](https://github.com/taylorotwell) in
[https://github.com/laravel/framework/pull/49003](https://github.com/laravel/framework/pull/49003)
- \[10.x] Prevent DB `Cache::get()` occur race condition by
[@&#8203;xdevor](https://github.com/xdevor) in
[https://github.com/laravel/framework/pull/49031](https://github.com/laravel/framework/pull/49031)
- \[10.x] Fix notifications being counted as sent without a "shouldSend"
method by [@&#8203;joelwmale](https://github.com/joelwmale) in
[https://github.com/laravel/framework/pull/49030](https://github.com/laravel/framework/pull/49030)
- \[10.x] Fix tests failure on Windows by
[@&#8203;hafezdivandari](https://github.com/hafezdivandari) in
[https://github.com/laravel/framework/pull/49037](https://github.com/laravel/framework/pull/49037)
- \[10.x] Add unless conditional on validation rules by
[@&#8203;michaelnabil230](https://github.com/michaelnabil230) in
[https://github.com/laravel/framework/pull/49048](https://github.com/laravel/framework/pull/49048)
- \[10.x] Handle string based payloads that are not JSON or form data
when creating PSR request instances by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/framework/pull/49047](https://github.com/laravel/framework/pull/49047)
- \[10.x] Fix directory separator CMD display on windows by
[@&#8203;imanghafoori1](https://github.com/imanghafoori1) in
[https://github.com/laravel/framework/pull/49045](https://github.com/laravel/framework/pull/49045)
- \[10.x] Fix mapSpread doc by
[@&#8203;timacdonald](https://github.com/timacdonald) in
[https://github.com/laravel/framework/pull/48941](https://github.com/laravel/framework/pull/48941)
- \[10.x] Tiny `Support\Collection` test fix - Unused data provider
parameter by [@&#8203;stevebauman](https://github.com/stevebauman) in
[https://github.com/laravel/framework/pull/49053](https://github.com/laravel/framework/pull/49053)
- \[10.x] Feat: Add color_hex validation rule by
[@&#8203;nikopeikrishvili](https://github.com/nikopeikrishvili) in
[https://github.com/laravel/framework/pull/49056](https://github.com/laravel/framework/pull/49056)
- \[10.x] Handle missing translation strings using callback by
[@&#8203;DeanWunder](https://github.com/DeanWunder) in
[https://github.com/laravel/framework/pull/49040](https://github.com/laravel/framework/pull/49040)
- \[10.x] Add Str::transliterate to Stringable by
[@&#8203;dwightwatson](https://github.com/dwightwatson) in
[https://github.com/laravel/framework/pull/49065](https://github.com/laravel/framework/pull/49065)
- Add Alpha Channel support to Hex validation rule by
[@&#8203;ahinkle](https://github.com/ahinkle) in
[https://github.com/laravel/framework/pull/49069](https://github.com/laravel/framework/pull/49069)

###
[`v10.32.1`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10321---2023-11-14)

[Compare
Source](https://github.com/laravel/framework/compare/v10.32.0...v10.32.1)

- \[10.x] Add `[@pushElseIf](https://github.com/pushElseIf)` and
`[@pushElse](https://github.com/pushElse)` by
[@&#8203;jasonmccreary](https://github.com/jasonmccreary) in
[https://github.com/laravel/framework/pull/48990](https://github.com/laravel/framework/pull/48990)

###
[`v10.32.0`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10320---2023-11-14)

[Compare
Source](https://github.com/laravel/framework/compare/v10.31.0...v10.32.0)

- Update PendingRequest.php by
[@&#8203;mattkingshott](https://github.com/mattkingshott) in
[https://github.com/laravel/framework/pull/48939](https://github.com/laravel/framework/pull/48939)
- \[10.x] Change array_key_exists with null coalescing assignment
operator in FilesystemAdapter by
[@&#8203;miladev95](https://github.com/miladev95) in
[https://github.com/laravel/framework/pull/48943](https://github.com/laravel/framework/pull/48943)
- \[10.x] Use container to resolve email validator class by
[@&#8203;orkhanahmadov](https://github.com/orkhanahmadov) in
[https://github.com/laravel/framework/pull/48942](https://github.com/laravel/framework/pull/48942)
- \[10.x] Added `getGlobalMiddleware` method to HTTP Client Factory by
[@&#8203;pascalbaljet](https://github.com/pascalbaljet) in
[https://github.com/laravel/framework/pull/48950](https://github.com/laravel/framework/pull/48950)
- \[10.x] Detect MySQL read-only mode error as a lost connection by
[@&#8203;cosmastech](https://github.com/cosmastech) in
[https://github.com/laravel/framework/pull/48937](https://github.com/laravel/framework/pull/48937)
- \[10.x] Adds more implicit validation rules for `present` based on
other fields by
[@&#8203;diamondobama](https://github.com/diamondobama) in
[https://github.com/laravel/framework/pull/48908](https://github.com/laravel/framework/pull/48908)
- \[10.x] Refactor set_error_handler callback to use arrow function in
`InteractsWithDeprecationHandling` by
[@&#8203;miladev95](https://github.com/miladev95) in
[https://github.com/laravel/framework/pull/48954](https://github.com/laravel/framework/pull/48954)
- \[10.x] Test Improvements by
[@&#8203;crynobone](https://github.com/crynobone) in
[https://github.com/laravel/framework/pull/48962](https://github.com/laravel/framework/pull/48962)
- Fix issue that prevents BladeCompiler to raise an exception when
temporal compiled blade template is not found. by
[@&#8203;juanparati](https://github.com/juanparati) in
[https://github.com/laravel/framework/pull/48957](https://github.com/laravel/framework/pull/48957)
- \[10.x] Fix how nested transaction callbacks are handled by
[@&#8203;mateusjatenee](https://github.com/mateusjatenee) in
[https://github.com/laravel/framework/pull/48859](https://github.com/laravel/framework/pull/48859)
- \[10.x] Fixes Batch Callbacks not triggering if job timeout while in
transaction by [@&#8203;crynobone](https://github.com/crynobone) in
[https://github.com/laravel/framework/pull/48961](https://github.com/laravel/framework/pull/48961)
- \[10.x] expressions in migration computations fail by
[@&#8203;tpetry](https://github.com/tpetry) in
[https://github.com/laravel/framework/pull/48976](https://github.com/laravel/framework/pull/48976)
- \[10.x] Fixes Exception: Cannot traverse an already closed generator
when running Arr::first with an empty generator and no callback by
[@&#8203;moshe-autoleadstar](https://github.com/moshe-autoleadstar) in
[https://github.com/laravel/framework/pull/48979](https://github.com/laravel/framework/pull/48979)
- fixes issue with stderr when there was "]" character. by
[@&#8203;nikopeikrishvili](https://github.com/nikopeikrishvili) in
[https://github.com/laravel/framework/pull/48975](https://github.com/laravel/framework/pull/48975)
- \[10.x] Fix Postgres cache store failed to put exist cache in
transaction by [@&#8203;xdevor](https://github.com/xdevor) in
[https://github.com/laravel/framework/pull/48968](https://github.com/laravel/framework/pull/48968)

###
[`v10.31.0`](https://github.com/laravel/framework/blob/HEAD/CHANGELOG.md#v10310---2023-11-07)

[Compare
Source](https://github.com/laravel/framework/compare/v10.30.1...v10.31.0)

- \[10.x] Allow `Sleep::until()` to be passed a timestamp as a string by
[@&#8203;jameshulse](https://github.com/jameshulse) in
[https://github.com/laravel/framework/pull/48883](https://github.com/laravel/framework/pull/48883)
- \[10.x] Fix whereHasMorph() with nullable morphs by
[@&#8203;MarkKremer](https://github.com/MarkKremer) in
[https://github.com/laravel/framework/pull/48903](https://github.com/laravel/framework/pull/48903)
- \[10.x] Handle `class_parents` returning false in
`class_uses_recursive` by
[@&#8203;RoflCopter24](https://github.com/RoflCopter24) in
[https://github.com/laravel/framework/pull/48902](https://github.com/laravel/framework/pull/48902)
- \[10.x] Enable default retrieval of all fragments in `fragments()` and
`fragmentsIf()` methods by [@&#8203;tabuna](https://github.com/tabuna)
in
[https://github.com/laravel/framework/pull/48894](https://github.com/laravel/framework/pull/48894)
- \[10.x] Allow placing a batch on a chain by
[@&#8203;khepin](https://github.com/khepin) in
[https://github.com/laravel/framework/pull/48633](https://github.com/laravel/framework/pull/48633)
- \[10.x] Dispatch 'connection failed' event in async http client
request by [@&#8203;gdebrauwer](https://github.com/gdebrauwer) in
[https://github.com/laravel/framework/pull/48900](https://github.com/laravel/framework/pull/48900)
- authenticate method refactored to use null coalescing operator by
[@&#8203;miladev95](https://github.com/miladev95) in
[https://github.com/laravel/framework/pull/48917](https://github.com/laravel/framework/pull/48917)
- \[10.x] Add support for Sec-Purpose header by
[@&#8203;nanos](https://github.com/nanos) in
[https://github.com/laravel/framework/pull/48925](https://github.com/laravel/framework/pull/48925)
- \[10.x] Allow setting retain_visibility config option on Flysystem
filesystems by [@&#8203;jnoordsij](https://github.com/jnoordsij) in
[https://github.com/laravel/framework/pull/48935](https://github.com/laravel/framework/pull/48935)
- \[10.x] Escape forward slashes when exploding wildcard rules by
[@&#8203;matt-farrugia](https://github.com/matt-farrugia) in
[https://github.com/laravel/framework/pull/48936](https://github.com/laravel/framework/pull/48936)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/Lapotor/RadioRoster-api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@siarheipashkevich
Copy link
Contributor

@nikopeikrishvili is it possible to set one of the formats for validation? For example I need to accept only:
Standard 6-Digit Hex Codes:
Format: #RRGGBB

@ahinkle
Copy link
Contributor

ahinkle commented Mar 11, 2024

@siarheipashkevich You may have to write a custom rule for that. Laravel validation doesn't generally accept PRs of argument exclusions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants