简体   繁体   English

如何在正则表达式中允许数字或数字/数字

[英]How to allow number or number/number in regular expression

I am using asp.net c#.I am using validation expression.I want my text field will accept 我正在使用asp.net c#。我正在使用验证表达式。我希望我的文本字段将接受

number\\number like 25\\14 or it will accept only number like 23 So i want 数字\\数字,例如25 \\ 14,否则它将仅接受数字,例如23,所以我要

13/ 13 13/13

or 要么

11 11

I am using this express ^[0-9]{1,2}//[0-9]{1,2} but it is accepting number/number like 12/12 but also i want to allow number also like 10 only but only two digits allow like 23 not 130/340 我正在使用此快递^ [0-9] {1,2} // [0-9] {1,2},但它接受数字/数字,例如12/12,但我也想允许数字也仅像10但只有两位数允许 23而不是130/340

I want error if user type number/ like 14/ 如果用户类型为数字/,例如14 /,我想报错

I want text field will accept 13/34 two digits number
text will accept 14
text field not accept only bracket 
text field not accept 13/ or /23

You can use this regex: 您可以使用此正则表达式:

^[1-9]\d(/[1-9]\d)?$

DEMO DEMO

You could do it like this it will allow (00-99) and (00-99)(00-99) 您可以这样操作,它将允许(00-99)和(00-99)(00-99)

[0-9]{2}(/[0-9]{2}){0,1}

So to the checklist 所以到清单

I want text field will accept 13/34 two digits number (YES -> accepted) Link 我希望文本字段接受13/34两位数字(是->接受) 链接

text will accept 14 (YES -> accepted) Link 文本将接受14 (是->接受) 链接

text field not accept only bracket (YES -> not accepted) 文本字段不只接受方括号(是->不接受)

text field not accept 13/ or /23 (YES -> not accepted) 文本字段不接受13 /或/ 23 (是->不接受)

Tested regex debugger https://www.debuggex.com 经过测试的正则表达式调试器https://www.debuggex.com

只需^[1-9][0-9](\\/[1-9][0-9]){0,1}$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM