简体   繁体   中英

Validate Decimal number with Mathematic Operator using RegEx in C#

I want to validate string decimal number with some mathematic operator using Regex like

<=-5.6
<10
>=10
10.5
<=-20.4
2.
-.2
>-5.

Invalid string like

<>5
=>5.6
5.6>=

This regex passes your test cases:

var regex = new Regex(@"^([<>]=?)?-?(\d+\.?|\d*\.?\d+)$");
bool isMatch = regex.IsMatch(testString);

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