954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

mask a string entered in textbox

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.

rexdon
Newbie Poster
12 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 
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

rexdon
Newbie Poster
12 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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.

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

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 . .

ChrisHunter
Posting Whiz in Training
276 posts since Feb 2011
Reputation Points: 36
Solved Threads: 28
 

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 ;)

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

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

ChrisHunter
Posting Whiz in Training
276 posts since Feb 2011
Reputation Points: 36
Solved Threads: 28
 

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

Munnazz
Light Poster
36 posts since Dec 2010
Reputation Points: 10
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: