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] Add check if the string is hex color #49068

Closed
wants to merge 2 commits into from
Closed

[10.x] Add check if the string is hex color #49068

wants to merge 2 commits into from

Conversation

michaelnabil230
Copy link
Contributor

This PR adds a to check if the string is a hex color

$isHexColor = Str::isHexColor('#FFFFFF');

// Or

$isHexColor = str('#FFFFFF')->isHexColor();

@michaelnabil230 michaelnabil230 changed the title [10.x] Add check if the string is color hex [10.x] Add check if the string is hex color Nov 21, 2023
@ahinkle
Copy link
Contributor

ahinkle commented Nov 21, 2023

What could be the practical use of this? While a validator rule would be valuable, a string helper is not likely to see frequent use.

@michaelnabil230
Copy link
Contributor Author

Hello @ahinkle,

Using Str::isHexColor() can be beneficial in various scenarios, including:

  • Unit Testing: It helps ensure the code correctly handles hex color codes and identifies potential issues related to invalid color codes.

  • Third-Party Integrations: It prevents errors caused by invalid color codes received from external sources when integrating with third-party APIs or libraries.

  • Data Cleaning and Sanitization: It filters out invalid hex color codes, ensuring data integrity when processing data from external sources or user input.

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.

3 participants