In my .NET MAUI App, I have Entrys that should allow positive double values. Also, I allow to switch Languages. Currently, I only support English and German.
Anyway, in English Culture Settings, „.“ is the decimal separator and in German it would be „,“.
In my Pixel 5 - API 33 (Android 13.0 - API 33) Emulator, I only get „.“ when I hit „,“ in German Language Setting and also when I hit it in English Language Settings.
Unfortunately, it is interpreted differently then and actually an input of „84.2“ is then stored as 842“.
Is there an easy way to deal with that, so that the values are stored and loaded correctly independent from the current Culture?
Also, is there an easy way to allow just positive values and also be able to have „0“ and „0.“ while typing, but not „.456“?
Or maybe some of you know a much easier way than parsing a certain Regex during TextChanged (what I currently do) to allow positive double values culture independent? Also want to store the values in SQLite then.
=========== Code of Entry TextChanged ======
private void EntryControl_TextChanged(object sender, TextChangedEventArgs e)
{
var entry sender as Entry;
var input entry.Text;
var match = Regex.Match(input, „^(0|0[.,][0-9]*|[1-9]+[.,]*[0-9]*)$“);
if (input.Length == 0)
{
return;
}
if (!match.Success)
{
entry.Text = e.OldTextValue;
}
entry.CursorPosition = e.NewTextValue.Length;
}