Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unity regular expressions

Hello I am using the following regex command to only allow numbers be inputted into a text field

Regex rgx = new Regex("[^0-9]"); 

however this obviously doesnt allow the inputting of positive and negative signs +/-. I would like to be able to input -9 for a negative value but when i do it comes back as 09 instead. Any help in getting the regular expression right would be appreciated.

like image 860
Alan Fletcher Avatar asked Apr 15 '26 22:04

Alan Fletcher


1 Answers

There you go, this one works 100% just tested to make sure ;)

Regex r = new Regex("^([-+]?)?[0-9]+(,[0-9]+)?$");
like image 129
Thalmann Avatar answered Apr 17 '26 13:04

Thalmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!