Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict to only English chars

Tags:

c#

winforms

I have a Winform with some edit boxes.

The form can be loaded in other languages too, like chinese! the requirement is that certain textboxes should accept only English chars for Example When user types in Tex box 1, it should be in english Whereas in if he types in Text box 2 and 3 it should be in Chinese ?

Is it possible to do something like this !

like image 814
siva Avatar asked Dec 03 '10 03:12

siva


People also ask

How do you restrict characters in input?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.

How do I allow only characters in a text box in react native?

To restrict an input field to only letters in React.Set the type of the input field to text . Add an onChange event handler that removes all characters but letters. Keep the input value in a state variable.


1 Answers

Yes, it's certainly possible. You can add a validation event handler that checks the character. You could have a dictionary of permissible characters, or if you restrict the character to a certain encoding (perhaps UTF-8), you could compare the character to a range of characters using < and >.

To be more specific: You can handle the KeyPress event. If e.KeyChar is invalid, set e.Handled to true.

Try this:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (System.Text.Encoding.UTF8.GetByteCount(new char[] { e.KeyChar }) > 1)
    {
        e.Handled = true;
    }
}
like image 159
Reinderien Avatar answered Sep 28 '22 11:09

Reinderien