Jump to content

Recommended Posts

Posted (edited)

This simple regular expression I came across on regexlib.com, will verify if a colour value is a "web safe" colour value.

I have used color in the function instead of colour, to match that of AutoIt's use of the American term(s).

Function and Example:

#include <Constants.au3>

MsgBox($MB_SYSTEMMODAL, '', '#FFFFFF: ' & _IsWebColor('#FFFFFF'))
MsgBox($MB_SYSTEMMODAL, '', '#EEFFCC: ' & _IsWebColor('#EEFFCC'))
MsgBox($MB_SYSTEMMODAL, '', '0x000033: ' & _IsWebColor('0x000033'))
MsgBox($MB_SYSTEMMODAL, '', '000033: ' & _IsWebColor('000033'))

; #FUNCTION# ====================================================================================================================
; Name ..........: _IsWebColor
; Description ...: Check whether a color value is a valid web color. Onl
; Syntax ........: _IsWebColor($sColor)
; Parameters ....: $sColor              - Valid web color.
; Return values .: Success - True
;                  Failure - False
; Author ........: guinness
; Related .......: http://html-color-codes.com/
; Link ..........: http://www.regexlib.com/REDetails.aspx?regexp_id=528
; Example .......: Yes
; ===============================================================================================================================
Func _IsWebColor($sColor)
    Return StringRegExp($sColor, '^(?:#|0[xX])?(([FfCc0369])\2){3}$') = 1 ; Also valid: (?i)^#?(([fc0369])\2){3}$
EndFunc   ;==>_IsWebColor
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 6 months later...
Posted

Added support for colours with a prefix of 0x or 0X.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...