I am doing validation on textbox
1) such as Do not allow to enter special character
2) only allow character & int
3) allow integer number only
4) select date from datepicker only. do not allow to enter from keyboard.
I am done using regex as well as with code . it show me message for perticular validation but typed key show in textbox
here is my code
private void checkvalidation(string Datatype, string txtBoxValue,string txtBoxName)
{
switch (Datatype.ToString().ToLower())
{
case "system.string":
var StringRegexExp = new Regex("^[a-zA-Z0-9 -()@,.]*$");
if (!Regex.IsMatch(txtBoxValue, "^[a-zA-Z0-9 -()@,.]*$"))
MessageBox.Show("Please do not enter special character.", "Validation", MessageBoxButton.OK);
if (txtBoxValue.Length > 0)
txtBoxValue.Remove(txtBoxValue.Length - 1);
break;
case "system.int32":
var IntegexExp = new Regex("^[0-9]+$");
if (!Regex.IsMatch(txtBoxValue, "^[0-9]+$"))
MessageBox.Show("Please enter numeric values.", "Validation", MessageBoxButton.OK);
break;
case "datePicker":
var DatepickerRegexExp = new Regex("^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)[0-9][0-9]$");
if (!Regex.IsMatch(txtBoxValue, "^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)[0-9][0-9]$"))
MessageBox.Show("Please select date from datepicker.", "Validation", MessageBoxButton.OK);
break;
}
}