Validate a hexadecimal color code

Total Post:412


 2223  View(s)
Rate this:

Hi All!

Please, I'm looking for a validation able to validate a CSS color code (e.g: #ffffff).

Conditions (you may know) are:
Begin => #;
strlen => 7 char with include #;
[a-fA-F0-9] in any combination or order;

Thanks in advance!

  1. Re: Validate a hexadecimal color code

    Hi Pravesh!

    You could try following line of code

    <script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.maskedinput.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            $.mask.definitions['h'] = "[A-Fa-f0-9]";
    <input id="hexacolor" type="text" />

    "jquery-1.7.1.min.js" provided by MVC application
    "jquery.maskedinput.js" you can download from following link

      Modified On Mar-29-2018 11:11:10 PM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.