internal bool IsValidCharacter(char character) { if (BoProp == null) return true; if (TextBoxControl == null) return true; if (BoProp.PropertyType.IsInteger()) { if ((character < '0' || character > '9') && character != 8 && character != '-') { return false; } if (character == '-' && TextBoxControl.SelectionStart != 0) { return false; } } else if (BoProp.PropertyType.IsDecimal()) { if ((character < '0' || character > '9') && character != '.' && character != 8 && character != '-') { return false; } if (character == '.' && TextBoxControl.Text.Contains(".")) { return false; } // In fact the char is valid, but we want the event to get handled in order to prevent double dots if (character == '.' && TextBoxControl.SelectionStart == 0) { TextBoxControl.Text = "0." + TextBoxControl.Text; TextBoxControl.SelectionStart = 2; TextBoxControl.SelectionLength = 0; return false; } if (character == '-' && TextBoxControl.SelectionStart != 0) { return false; } } return true; } }