How to limit input

  • Thread starter Thread starter ad
  • Start date Start date
ad said:
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
 
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.
 
Thanks,
How can I use regex expression?


Duggi said:
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.
 
Thanks,
How can I use regex expression?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top