Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i wnat to allow only +5.00 or -6.0 which is numeric value with sign is there any function in C# for such validation.where sign is only at start of the number.
Posted

If you are storing values in a string then use string.Contains to figure out if there are more than one - sign in the string.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Mar-13 13:57pm    
We don't really know exactly OP's situations, but sometimes it may be needed (with "if"), a 5.
—SA
Abhinav S 18-Mar-13 22:57pm    
Thank you SA.
vishal_h 20-Mar-13 0:34am    
thanks for reply..but in my requirement i want to allow sign only at start of the numeric value.
The problem is not correctly formulated. Most likely, you simply need certain string formatting representing a numeric value. It depends on the data type, but let's assume it's System.Int32, alias is int. In this case, take a look:
http://msdn.microsoft.com/en-us/library/system.int32.tostring.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

This is all you need. For other type, the situation is nearly the same.

—SA
 
Share this answer
 
Comments
Abhinav S 18-Mar-13 12:47pm    
My 4 this time. I guess the OP has a string variable and that string could contain multiple - symbols.
Just my guess. of course!
Sergey Alexandrovich Kryukov 18-Mar-13 13:56pm    
OK, I understand it; thank you, Abhinav.
—SA

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