'Regex change color background of input field

I want to make a generic input field with regex dynamic matching. It's work if I put a static color (for example Color.red) but if I give the color in script parameter it doesn't work....

public class InputRegex : MonoBehaviour
{
    public string regexPattern;
    public Color correctMatchColor;
    public Color wrongMatchColor;

    private InputField inputField;

    void Start()
    {
        inputField = this.gameObject.GetComponent<InputField>();
    }

    public void matching(string input)
    {
        Debug.Log(input);
        Debug.Log(correctMatchColor);
        Debug.Log(wrongMatchColor);
        if (System.Text.RegularExpressions.Regex.IsMatch(input, regexPattern)) {
            inputField.image.color = correctMatchColor;
        } else {
            inputField.image.color = wrongMatchColor;
        }
    }
}

It's make a transparent background in all cases...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source