by default i want to ask the user to enter text in textbox in pattern: _x_____.
for example : 0x81A00.
User should be able to allow both numeric and alphabet.


for this i used

TextBox.Mask="0x00000";

but this allows user to enter only numeric values..but i need to enter alphabet also.

Recommended Answers

All 7 Replies

Hello, rexdon.
Are you looking for something like this: C# Hex Mask for maskedtextbox input? ;)

Actually it was not clear for me..i want the user to enter in text box in hex format,and that too of specified length.While running the form the textbox should initially display as :

Hex ID: _x_______

For example user enters:

Hex ID: 0x810A000

Ok, here was similar question: maskedTextBox works for hexadecimal input.

So, I've suggested you to see that link in my previous post. The solution might be like this:
1. Specify mask, that accepts all Alphanumeric characters. So you restrict the length and basic format (the second character always would be "x").
2. And then - listen to KeyPress event for further restrictions. You may choose re restriction from the first link I gave you (manually checking characters), or from the second (there's a link for a regular expression for the hexadecimal numbers), or make something your own.

by default i want to ask the user to enter text in textbox in pattern: _x_____.

User should be able to allow both numeric and alphabet.

but this allows user to enter only numeric values..but i need to enter alphabet also.

This suggests that you don't want the user to be able to enter something made up of entierly numeric charactors or entierly made up of alphabetic charactors. If so i don't think theres a way to do it because setting it as a string means that everything (even if all charactors are numeric) are seen as being a string and not numeric.

On question of having _x______ as the default value of the text box just set the value property of the textbox to be initialised with that value i think . .

Hi, Chris.
I've provided the solution, that would give the OP such functionality.

set the value property of the textbox to be initialised with that value i think . .

I don't think it's more handy approach. Because:
1. You have to show/hide/replace mask along user inputs text.
2. You still need to take control over user input (to validate the users input).

We have such a good control, MaskedTextBox. Yes, it's not almighty, so we sometimes need to help it to handle specific task. But still, there're a lot of pre-defined things, so there's no need to reinvent the wheel ;)

Arr my apologies i have to admit i didn't read the thread properly before replying

Use ajax masking to do this ......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.