digitalwise
asked on
We are having an issue with data being sent with non-numeric characters despite RegEx
If we send the value 100 to the save in our C# .NET project, it saves ok. But if we send $100 to the save, it does not. We are using Regex to strip it.
What is causing that??
dataIndicator.GPRPUM = gprpum.Text.Trim() != "" ? decimal.Parse(Regex.Replace(gprpum.Text, "[^-.0-9]", "")) : (decimal?)null;
What is causing that??
Regex.Replace(a, "[^-.0-9]", "")
will strip anything else than number decimal and "-". This "-" will cause issue in converting to decimal, try using [^.0-9]
ASKER
PlusOne - you gave me back my exact line of code. Najam - a decimal should take a negative number and we might be passing negative numbers to the field.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Digitalwise
no sir i can you new code :)
Text.Trim() != "" ? decimal.Parse(Regex.Replac e(gprpum.T ext, "[^-.$0-9]", "")) : (decimal?)null;
no sir i can you new code :)
Text.Trim() != "" ? decimal.Parse(Regex.Replac
ASKER
The save is with this value because if i take out the dollar sign we are using for display, it saves just fine. For some reason the regex isn't working.
ASKER
PlusOne - that would leave the $ in the value and I want to strip it out.
ASKER
It was related to the Telerik input box. Fixed but you help sort it out.
use this
Open in new window