The format I would like to allow in my text boxes are comma delimited lists followed by a line break in between the comma delimited lists. Here is an example of what I want from the user:
我想在文本框中允许的格式是逗号分隔列表,后面是逗号分隔列表之间的换行符。下面是我想从用户那里得到的一个例子:
1,2,3
1,2,4
1,2,5
1,2,6
So far I have limited the user using this ValidationExpression:
到目前为止,我对使用ValidationExpression的用户进行了限制:
^([1-9][0-9]*[]*[ ]*,[ ]*)*[1-9][0-9]*$
However with that expression, the user is only able to enter one row of comma delimited numbers.
但是,使用该表达式,用户只能输入一行逗号分隔的数字。
How can proceed to accept multiple rows by accepting line breaks?
如何通过接受换行符来接受多个行?
1 个解决方案
#1
3
It is possible to check if the input has the correct format. I would recommend to use groups and repeat them:
可以检查输入是否有正确的格式。我建议使用组并重复它们:
((\d+,)+\d+\n?)+
But to check if the matrix is symmetric you have to use something else then regex.
但是要检查矩阵是否对称,你必须使用其他的东西,然后regex。
Check it out here: https://regex101.com/r/GqtOuQ/2/
看看这里:https://regex101.com/r/GqtOuQ/2/
If you want to be a bit more user friendly it is possible to allow as much horizontal spaces as the user wants to add between the number and comma. This can be done with he regex group \h
which allows every whitespace except \n
.
如果您想要对用户更友好一点,可以在数字和逗号之间添加尽可能多的水平空格。这可以用he regex group \h完成,它允许除\n之外的所有空格。
The regex code looks now a bit more messy:
regex代码现在看起来有点混乱:
((\h*\d+\h*,\h*)+\h*\d+\h*\n?\h*)+
Check this out here: https://regex101.com/r/GqtOuQ/3
看看这里:https://regex101.com/r/GqtOuQ/3
Here is the version that should work with .NET:
这是一个与。net兼容的版本:
(([ \t]*\d+[ \t]*,[ \t]*)+[ \t]*\d+[ \t]*\n?[ \t]*)+
#1
3
It is possible to check if the input has the correct format. I would recommend to use groups and repeat them:
可以检查输入是否有正确的格式。我建议使用组并重复它们:
((\d+,)+\d+\n?)+
But to check if the matrix is symmetric you have to use something else then regex.
但是要检查矩阵是否对称,你必须使用其他的东西,然后regex。
Check it out here: https://regex101.com/r/GqtOuQ/2/
看看这里:https://regex101.com/r/GqtOuQ/2/
If you want to be a bit more user friendly it is possible to allow as much horizontal spaces as the user wants to add between the number and comma. This can be done with he regex group \h
which allows every whitespace except \n
.
如果您想要对用户更友好一点,可以在数字和逗号之间添加尽可能多的水平空格。这可以用he regex group \h完成,它允许除\n之外的所有空格。
The regex code looks now a bit more messy:
regex代码现在看起来有点混乱:
((\h*\d+\h*,\h*)+\h*\d+\h*\n?\h*)+
Check this out here: https://regex101.com/r/GqtOuQ/3
看看这里:https://regex101.com/r/GqtOuQ/3
Here is the version that should work with .NET:
这是一个与。net兼容的版本:
(([ \t]*\d+[ \t]*,[ \t]*)+[ \t]*\d+[ \t]*\n?[ \t]*)+