Link to home
Start Free TrialLog in
Avatar of digitalwise
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.

dataIndicator.GPRPUM = gprpum.Text.Trim() != "" ? decimal.Parse(Regex.Replace(gprpum.Text, "[^-.0-9]", "")) : (decimal?)null;

Open in new window


What is causing that??
Avatar of plusone3055
plusone3055
Flag of United States of America image

The DollarSign is making it invalid

use this

dataIndicator.GPRPUM = gprpum.Text.Trim() != "" ? decimal.Parse(Regex.Replace(gprpum.Text, "[^-.$0-9]", "")) : (decimal?)null;

Open in new window

Regex.Replace(a, "[^-.0-9]", "")

Open in new window

will strip anything else than number decimal and "-". This "-" will cause issue in converting to decimal, try using [^.0-9]
Avatar of digitalwise
digitalwise

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
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Digitalwise

no sir i can you new code :)

Text.Trim() != "" ? decimal.Parse(Regex.Replace(gprpum.Text, "[^-.$0-9]", "")) : (decimal?)null;
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.
PlusOne - that would leave the $ in the value and I want to strip it out.
It was related to the Telerik input box.   Fixed but you help sort it out.