match Color value by regex - Android java.util.regex

Android examples for java.util.regex:Character Pattern

Description

match Color value by regex

Demo Code


//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    private static final String V_COLOR = "^[a-fA-F0-9]{6}$";

    public static boolean Color(String value) {
        return match(V_COLOR, value);
    }//from   w w  w . ja va2 s .  c  om

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related Tutorials