问题锁定用户输入 [英] Problem Locking user input
问题描述
我正在制作一个Windows窗体应用程序。在整个过程中,我有很多文本框。我推迟到现在为止检查用户输入是一个有效的输入。
我尝试了以下(取自其他地方):
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;
}
但它并没有真正起作用,我不理解它。我想要一个小数点允许,有时候空格,一些文本框不能拥有它们,所有文本框的数字但没有字符或其他特殊字符,如&或$。
我第一次尝试的方法是取文本,将其输入字符串,读取它的最后一个输入,如果文本不被允许,删除last textbox string element:
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);
}
但由于某种原因它实际上并没有删除它。发生的事情是暂时删除最后一个元素,但是下一个用户输入随后被省略,现在允许第一个非法输入。重申:
输入1:010f
输出1:010
输入2(下次按键输入):010fa
输出2:010f
我需要的是真正消除这种邪恶的输入。帮助我:)
推荐答案
))
{
MessageBox :: Show(地址2:无效值);
}
其他
{
this-> textBox2-> Text = this-> textBox1-> Text;
}
" )) { 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);
}
但出于某种原因我实际上并没有删除它。发生的事情是暂时删除最后一个元素,但是下一个用户输入随后被省略,现在允许第一个非法输入。重申:
输入1:010f
输出1:010
输入2(下次按键输入):010fa
输出2:010f
我需要的是真正消除这种邪恶的输入。帮助我:)
首先,正确标记您的问题。然后,首先,请参阅我最近的回答:数字必须是最多9位的数字 [ ^ ]。
阅读整个帖子;它会给你一些好主意。如有任何疑问,请在评论这篇文章时提出进一步的问题。
-SA
First of all, tag your question properly. Then, to start with, see my recent answer: number must be numeric up to 9 digits[^].
Read the whole thread; it will give you some good ideas. Please ask further questions by commenting this post, in case of any doubt.
—SA
这篇关于问题锁定用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!