Add namespace: using System.Text.RegularExpressions;
if (Regex.IsMatch(txt_number.Text, @"\d+(\.\d{1,2})?")) { //valid Number // Do something with value } else { //invalid Number lbl_error.Text = "Please enter a valid number"; return; }
decimal d; if (decimal.TryParse(txt_number.Text, out d)) { //valid Number // Do something with value } else { //invalid Number lbl_error.Text = "Please enter a valid number"; return; }