Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all,
i need a regular expression for accepting numbers and also negative numbers with - sign.

Thanx in advance
Venkatesh
Posted

Try:
-?\d+


Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
Comments
narla.venkatesh 18-Mar-13 7:06am    
It should also accept numbers without any sign to its prefix
OriginalGriff 18-Mar-13 7:35am    
It does - did you try it?
That's what the '?' does - "match zero or one of these"
Get a copy of Expresso, and look at it's description of the expression.
Hey you can use this
C#
Regex.IsMatch(inputString, @"^[\-\+]\s*\d+\s*$");
 
Share this answer
 
Comments
narla.venkatesh 18-Mar-13 7:02am    
it should also accept integers without any sign

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900