我在vb.net工作。我想创建一个验证器,检查用户是否输入了仅数百的值。即100,200,300,400,500 ... 1100,1200,1300,1400 ... 100000,100100等。提前谢谢!
答案 0 :(得分:1)
这样的事情应该有效:
^[1-9][0-9]*00$
这将匹配从1到9的单个十进制数字,后跟零或更多的任何十进制数字,后跟两个0
。开始(^
)和结束($
)锚点确保输入中不允许其他字符。例如:
Dim match = Regex.Match("1200", "^[1-9][0-9]*00$")
Console.WriteLine(match.Success) // True
答案 1 :(得分:1)
为什么要使用正则表达式?这将获得相同的结果并且表现更好。
If inputString.EndsWith("00") And Integer.TryParse(inputString, 0) Then
'Is a number in the hundreds...
End If
这是一个活泼的小提琴: http://dotnetfiddle.net/Z0iwt6
答案 2 :(得分:0)
这样的事情应该有效:
Dim result As Double = 0
If Double.TryParse(Output(0), result) AndAlso Math.IEEERemainder(result, 100) = 0 Then
'process input here
End If