I have a WPF application in which I have a hook at PreviewTextInput, through that I get the currently entered character and I have the string already entered. Given this I need to write the following function :
bool ShouldAccept(char newChar,string existingText)
existingText can be comma seperated valid numbers(including exponential) and it should just return false when invalid characters are pressed.
My code(if else based) currently has a lot of flaws, I wanted to know if there is any smart way to do it.
I finally did it using Regex,
So basically my ShouldAccept looks like this :
In all its just 50 lines of code. I could have combined all the regex but this is much easier to read.