- Home /
The question is answered, right answer was accepted
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.
Thanking You
Answer by Alan Fletcher · Mar 23, 2013 at 01:05 AM
this works for anyone who comes across a similar prob
Regex rgx = new Regex("[^-][^0-9]+");
The RegEx you posted does the opposite. Yours evaluates to false for all numbers. What you want is: Regex rgx = new Regex("[-]?[0-9]+");
Follow this Question
Related Questions
How to draw an arrow from fps contoller 1 Answer
Multiple Cars not working 1 Answer
Mathf.pingpong 4 Answers
Limiting player movement (Partially done) 1 Answer
how to get in game numerical input 1 Answer