By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

How to limit input

P: n/a
ad
I want to limit the input of usr to 0..9 or a..z
How can I do that?
Dec 12 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"ad" <fl****@wfes.tcc.edu.twwrote in message
news:OT**************@TK2MSFTNGP06.phx.gbl...
>I want to limit the input of usr to 0..9 or a..z
How can I do that?
There are lots of ways. One would be to use a MaskedTextBox control.

Pete
Dec 12 '06 #2

P: n/a
Hi
If you are using winforms Masked Textbox would be appropriate choice.

Drag drop masked text box on to window form and set the mask property
to custom mask and put mask as AAAAAAAAAAAAAAAAAAA.

only pain point is you need to know the number of chars.

Hope this solves the issue at hand.

Thanks
-Srinivas.

ad wrote:
I want to limit the input of usr to 0..9 or a..z
How can I do that?
Dec 12 '06 #3

P: n/a
ad
Thanks,
How can I use regex expression?
"Duggi" <Du***************@gmail.com>
???????:11**********************@j44g2000cwa.googl egroups.com...
Hi
If you are using winforms Masked Textbox would be appropriate choice.

Drag drop masked text box on to window form and set the mask property
to custom mask and put mask as AAAAAAAAAAAAAAAAAAA.

only pain point is you need to know the number of chars.

Hope this solves the issue at hand.

Thanks
-Srinivas.

ad wrote:
>I want to limit the input of usr to 0..9 or a..z
How can I do that?

Dec 12 '06 #4

P: n/a
On Tue, 12 Dec 2006 14:02:47 +0800, ad wrote:
Thanks,
How can I use regex expression?

"Duggi" <Du***************@gmail.com>
???????:11**********************@j44g2000cwa.googl egroups.com...
>Hi
If you are using winforms Masked Textbox would be appropriate choice.

Drag drop masked text box on to window form and set the mask property
to custom mask and put mask as AAAAAAAAAAAAAAAAAAA.

only pain point is you need to know the number of chars.

Hope this solves the issue at hand.

Thanks
-Srinivas.

ad wrote:
>>I want to limit the input of usr to 0..9 or a..z
How can I do that?
Hey ad,

Here's a small program to do what you want

First, put this in the class imports

using System.Text.RegularExpressions;

Then run this
public static void Main()
{
//
// Get the input
//
string inputString="aA";
Console.WriteLine(IsValid(inputString));
Console.ReadLine();
}

//
// This function validates the input
//
static bool IsValid(string s){
//
// Create a regex
//
Regex r = new Regex(@"^[0-9a-z]*$");
//
// Check if the input matches
//
return r.IsMatch(s);
}
--
Bits.Bytes
http://bytes.thinkersroom.com
Dec 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.