41

validatecolor

validate_color
SYNOPSIS

validate_color($color, $with_hashmark=true)

DESCRIPTION

validate_color retourne true si $color est une couleur RVB valide.

Si $with_hashmark vaut true, le # (DIÈSE) en tête est facultatif. Sinon, $color doit contenir exactement 6 chiffres hexadécimaux.

EXEMPLE
php > require 'library/validatecolor.php';
php > var_dump(validate_color('#ffcc00'));
bool(true)
php > var_dump(validate_color('ffcc00', false));
bool(true)
php > var_dump(validate_color('#fc0', false));
bool(false)
CODE
  1. function validate_color($color, $with_hashmark=true) {
  2.     return preg_match($with_hashmark ? '/^#?([0-9A-F]){6}$/i' : '/^([0-9A-F]){6}$/i', $color);
  3. }

Commentaires

Votre commentaire :
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip aide 2000

Entrez un maximum de 2000 caractères.
Améliorez la présentation de votre texte avec les balises de formatage suivantes :
[p]paragraphe[/p], [b]gras[/b], [i]italique[/i], [u]souligné[/u], [s]barré[/s], [quote]citation[/quote], [pre]tel quel[/pre], [br]à la ligne,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]commande[/code], [code=langage]code source en c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].