How to do currency-based number validation? - c#

I have a Winforms Application, in which I have a Combo Box, and a text box. Combo box has Currency symbols as follows:
USD
GBP
CAD
AUD
JPY
EUR
ISK
PLZ
TRL
etc ..
The user first selects one currency symbol from the above, and then types in a value in a text box, such as, $32.50, etc ..
I need to validate the string that he types into the text box, based on the currency he selected in the Combo Box. Each currency has its own way of writing money values.
For example, if the user selects USD then all of these typed strings shouble be reported as valid:
223.3
2244.44
$3,754.24
However if the user selects TRL (Turkish Lira), in which symbol is placed after the numeric value (to its right), then these should be valid:
223.3
2244.44
3,754.24 TL
How can I achieve this kind of validation ?

Since you already know the selected language, the easiest solution would be to not validate the symbol. Place an empty label on each side of the textbox and assign them according to the selected currency's symbol. Now you only have to worry about the decimal part, which is quite easy.

Related

convert text box value (12000) to time format (1:20:00) in UWP

I have a project which has simply one text box and some sort of buttons acts as numeric input, This is my question : when I enter a number like 12000 into the text box, it suddenly changes the format to 1:20:00 and display in same text box. can it be handled by Text_changed (event handler)? if yes what is code behind ?

Using Winforms, how can I insert the value of a masked textbox into a database? [duplicate]

I have a MaskedTextBox with this mask (999) 999 9999.
When user inputs a number the text property would give this to me :
(0881) 444 5445
But I want to save the raw text to database field like this: 08814445445.
How can I do that?
Based on what I found here you can set the TextMaskFormat-Property to MaskFormat.ExcludePromptAndLiterals. That should be you solution.
The MaskFormat-Enumeration holds some "options" for the MaskedTextBox.
They are:
ExcludePromptAndLiterals Return only text input by the user.
IncludeLiterals Return text input by the user as well as any literal characters defined in the mask.
IncludePrompt Return text input by the user as well as any instances of the prompt character.
IncludePromptAndLiterals Return text input by the user as well as any literal characters defined in the mask and any instances of the prompt character.
The default is
IncludeLiterals
It's Work for me
Just Change Property Value
Try setting the maskedTextBox.TextMaskFormat property to
MaskFormat.ExcludePromptAndLiterals

WPF: Validation of multiple textboxes

Here's the situation:
I've got 3 textboxes where one put First Name, Last Name and Age respectively. Label with big red "!" shall be only visible when:
Any of the textboxes has no content OR Age (third textbox) is a negative number OR Age is bigger than int.MaxValue.
I already got two validation rules (one for first/last name and another for age). What do I do now? Do I need some kind of converter that checks all three input fields and returns true/false? How to implement this in XAML?
You can use IDataErrorInfo to validate the fields - see this article which explains how to use it. You'll just need to adapt it to have one field displaying errors instead of individual ones for all three.

How to stop entering the text, when user going out of autoCompleteMode text c#

Iam using AutoCompleteMode to my textbox. It will append the Bank names to my textbox. So when I started typing with the first leter all the Bank names with first lettre will come to dropdownlist to my textbox. Now my question is
If user try to entre the data which is not im my dropdownlist, the user should not able to entre the text. So i want user to entr the existing bank names only.
Iam using AutoCompleteCustomSource to the textbox for dropdown.
try something like:
bool foundSome = false;
foreach (var bankName in col)
{
foundSome = bankName.StartsWith(textBox.text);
}
if (foundSome)
//Do some action
You can write this code in 'Validating' to preform for each char inserted in txtbox.
the best way to achieve your requierement is to use 1 textbox and 1 combobox. They both should point to the same collection.
Textbox will behave in autocomplete mode as you described. Once you type, combobox value will be set to first matching value from your collection. If no value matches - combobox value should be set to null or default data.
Combobox will store only corresponding data subset with no possibility to edit the chosen text.
Validation and data retrieval will be done from Combobox value.
Advantages of this approach:
- With large sets of data it will be easier for user to find what he/she needs.
- Lesser code to check if input value belongs to data set or to force belonging.
- No validation is needed.
Possible shortcomings:
- One more control at form.
- Logic to synchronize textbox's text and combobox collection should be implemented.

Set population field validation in masked text box

Hi I am new to C# I have one problem in masked text box
Population range is 1,000 to 12,00,00,00,000
My problem is when enter 1000 in masked text box it will be taken as 1,000 like when i enter 12000 it will considered as 12,000 like default it will arranged in ,.
How can i do it? Please provide if any solution.
What is the Mask property set to? Try making it: #,##0.

Categories