Permalink
Browse files

InputText plugin: Fixed issues with numeric input when typing.

Now only accepts a '-' at the beginning of the text for negative values, and '.' for decimals places.
Both of the above can only be used once.
  • Loading branch information...
1 parent f50c748 commit c067e4ff23fd1727bf97afb0b3d41a8b0e731fbc @brianferguson brianferguson committed Nov 28, 2016
Showing with 17 additions and 1 deletion.
  1. +17 −1 Plugins/PluginInputText/InputBox.cs
@@ -50,7 +50,23 @@ private void txtInput_KeyPressed(object sender, KeyPressEventArgs e)
{
if (_Numeric)
{
- e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
+ if (!char.IsControl(e.KeyChar) && (!char.IsDigit(e.KeyChar))
+ && (e.KeyChar != '.') && (e.KeyChar != '-'))
+ {
+ e.Handled = true;
+ }
+
+ // only allow one decimal point
+ if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
+ {
+ e.Handled = true;
+ }
+
+ // only allow minus sign at the beginning
+ if (e.KeyChar == '-' && (sender as TextBox).Text.Length > 0)
+ {
+ e.Handled = true;
+ }
}
}

0 comments on commit c067e4f

Please sign in to comment.