Menerima salah satu dari 1, 2, x atau x, atau tidak sama sekali

private Boolean patternIsMatch(String text) {
	// Alternatives; one of 1, 2, x or X, or nothing is accepted pattern.
	Regex pattern = new Regex(@"^([12xX]{1}|^)$");
	return pattern.IsMatch(text);
}
private void textBoxAnswer_TextChanged(object sender, EventArgs e) {
	if (!patternIsMatch(textBoxAnswer.Text)) {                
		MessageBox.Show(textBoxAnswer.Text + " = Felaktigt värde");
		textBoxAnswer.Text = "";
	}
}
Richard Holm