Hi,
I'm making a windows forms application. Throughout I have a lot of text boxes. Something I put off until now was checking the user input is a valid input.
I tried the following (taken from elsewhere):
if (! System::Text::RegularExpressions::Regex::IsMatch(this->textBox1->Text, "^[0-9afA-F]{1,3}$" ))
{
MessageBox::Show ( "Address 2: Invalid value" );
}
else
{
this->textBox2->Text = this->textBox1->Text;
}
But it doesn't really work as I want and I dont understand it. I want one decimal point allowed, sometimes spaces, some textboxes cant have them though, and numbers for all textboxes but no characters or other special characters like & or $.
The way I first tried was to take the text, input it to a string, read it's last input, and if the text wasnt allowed, delete the last textbox string element:
int lastChar = myStr->Length - 1;
if( ! Char::IsDigit(myStr, lastChar))
{
myStr = myStr->Remove(lastChar);
this->textBox1->Text->Remove(lastChar);
}
But for some reason it doesnt actually delete it. What happens is it temporarily removes the last element but the next user input is then omitted with the first illegal input now allowed. Reiterating:
Input1 : 010f
Output1: 010
Input2 (next keystroke input): 010fa
Output2: 010f
What I need is to actually eradicate this evil input. Help me :)