diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index ccda7e7dff..3610ac21b0 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -629,34 +629,20 @@ namespace BizHawk.MultiClient private void WatchListView_AfterLabelEdit(object sender, LabelEditEventArgs e) { - /* - // Determine if label is changed by checking for null. - if (e.Label == null) - return; + if (e.Label == null) //If no change + return; - // ASCIIEncoding is used to determine if a number character has been entered. - ASCIIEncoding AE = new ASCIIEncoding(); - // Convert the new label to a character array. - char[] temp = e.Label.ToCharArray(); - - // Check each character in the new label to determine if it is a number. - for(int x=0; x < temp.Length; x++) - { - // Encode the character from the character array to its ASCII code. - byte[] bc = AE.GetBytes(temp[x].ToString()); - - // Determine if the ASCII code is within the valid range of numerical values. - if(bc[0] > 47 && bc[0] < 58) - { - // Cancel the event and return the lable to its original state. - e.CancelEdit = true; - // Display a MessageBox alerting the user that numbers are not allowed. - MessageBox.Show ("The text for the item cannot contain numerical values."); - // Break out of the loop and exit. - return; - } - } - */ + char[] temp = e.Label.ToCharArray(); + if (InputValidate.IsValidUnsignedNumber(temp)) //TODO: + { + //TODO: Change address to this new value + //TODO: show Edit watch dialog + } + else + { + MessageBox.Show("Invalid number!"); + //TODO: Restore original address value + } } private void RamWatch_LocationChanged(object sender, EventArgs e) diff --git a/BizHawk.Util/BizHawk.Util.csproj b/BizHawk.Util/BizHawk.Util.csproj index bd5ba6f7a2..cdef33a67c 100644 --- a/BizHawk.Util/BizHawk.Util.csproj +++ b/BizHawk.Util/BizHawk.Util.csproj @@ -89,6 +89,7 @@ Form + diff --git a/BizHawk.Util/InputValidate.cs b/BizHawk.Util/InputValidate.cs new file mode 100644 index 0000000000..2eb7583d49 --- /dev/null +++ b/BizHawk.Util/InputValidate.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk +{ + /// + /// Includes helper functions to validate user input + /// + public static class InputValidate + { + public static bool IsValidUnsignedNumber(char[] input) + { + ASCIIEncoding AE = new ASCIIEncoding(); + // Check each character in the new label to determine if it is a number. + for (int x = 0; x < input.Length; x++) + { + // Encode the character from the character array to its ASCII code. + byte[] bc = AE.GetBytes(input[x].ToString()); + + // Determine if the ASCII code is within the valid range of numerical values. + if (bc[0] < 47 || bc[0] > 58) + return false; + } + return true; + } + } +}