File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -103,20 +103,22 @@ private bool canAddCharacter(char character)
103103 // discard control/special characters.
104104 return false ;
105105
106- var currentNumberFormat = CultureInfo . CurrentCulture . NumberFormat ;
107-
108- switch ( InputProperties . Type )
106+ if ( InputProperties . Type . IsNumerical ( ) )
109107 {
110- case TextInputType . Decimal :
111- return char . IsAsciiDigit ( character ) || currentNumberFormat . NumberDecimalSeparator . Contains ( character ) ;
108+ bool validNumericalCharacter = false ;
112109
113- case TextInputType . Number :
114- case TextInputType . NumericalPassword :
115- return char . IsAsciiDigit ( character ) ;
110+ var currentNumberFormat = CultureInfo . CurrentCulture . NumberFormat ;
116111
117- default :
118- return true ;
112+ validNumericalCharacter |= char . IsAsciiDigit ( character ) ;
113+ validNumericalCharacter |= selectionLeft == 0 && currentNumberFormat . NegativeSign . Contains ( character ) ;
114+
115+ if ( InputProperties . Type == TextInputType . Decimal )
116+ validNumericalCharacter |= currentNumberFormat . NumberDecimalSeparator . Contains ( character ) ;
117+
118+ return validNumericalCharacter ;
119119 }
120+
121+ return true ;
120122 }
121123
122124 private bool readOnly ;
Original file line number Diff line number Diff line change @@ -66,6 +66,20 @@ public static bool IsPassword(this TextInputType type)
6666 }
6767 }
6868
69+ public static bool IsNumerical ( this TextInputType type )
70+ {
71+ switch ( type )
72+ {
73+ case TextInputType . Number :
74+ case TextInputType . NumericalPassword :
75+ case TextInputType . Decimal :
76+ return true ;
77+
78+ default :
79+ return false ;
80+ }
81+ }
82+
6983 public static bool SupportsIme ( this TextInputType type ) => type == TextInputType . Name || type == TextInputType . Text ;
7084 }
7185}
You can’t perform that action at this time.
0 commit comments