c# - How to allow only decimals in TextBox in WPF? -
i have 2 textbox
in wpf, , want 1 of them allow integer inputs , other 1 decimal inputs precision of two. looks this:
<label>price:</label> <textbox name="price" previewtextinput="decimalvalidationtextbox" text="{binding path=price}" /> <label>mileage:</label> <textbox name="mileage" previewtextinput="integervalidationtextbox" text="{binding path=mileage}" />
and 2 handler this:
private void decimalvalidationtextbox(object sender, textcompositioneventargs e) { regex regex = new regex("^[0-9]+([.][0-9]{1,2})?$"); e.handled = regex.ismatch(e.text); } private void integervalidationtextbox(object sender, textcompositioneventargs e) { regex regex = new regex("[^0-9]+"); e.handled = regex.ismatch(e.text); }
the point 1 used integers, namely integervalidationtextbox
works fine, , can type integer values. problem first 1 used decimals, namely decimalvalidationtextbox
. can write except numbers in there. ideas how allow decimals of precision 2 in textbox
?
Comments
Post a Comment