简体   繁体   中英

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

number\\number like 25\\14 or it will accept only number like 23 So i want

13/ 13

or

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

I want error if user type number/ like 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

You could do it like this it will allow (00-99) and (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

text will accept 14 (YES -> accepted) Link

text field not accept only bracket (YES -> not accepted)

text field not accept 13/ or /23 (YES -> not accepted)

Tested regex debugger https://www.debuggex.com

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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