This question already has an answer here:
(这个问题已经在这里有了答案:)
I need a regex that will accept only digits from 0-9 and nothing else.
(我需要一个正则表达式,它将只接受0-9之间的数字,而不能接受其他任何东西。)
No letters, no characters. (没有字母,没有字符。)
I thought this would work:
(我认为这可以工作:)
^[0-9]
or even
(甚至)
d+
but these are accepting the characters : ^,$,(,), etc
(但这些接受字符:^,$,(,)等)
I thought that both the regexes above would do the trick and I'm not sure why its accepting those characters.
(我以为上面的两个正则表达式都可以解决问题,我不确定为什么它接受那些字符。)
EDIT:
(编辑:)
This is exactly what I am doing:
(这正是我在做什么:)
private void OnTextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch("^[0-9]", textbox.Text))
{
textbox.Text = string.Empty;
}
}
This is allowing the characters I mentioned above.
(这允许我上面提到的字符。)
ask by mo alaz translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…