Reputation: 363
How can I change masked text box properties for IP address input? For example
private void Interneta_savienojums_Load(object sender, EventArgs e)
{
maskedTextBox1.Text = " . . . ";
maskedTextBox1.PromptChar = ' ';
maskedTextBox1.Mask = "009.009.009.900";
maskedTextBox1.ResetOnSpace = false;
maskedTextBox1.SkipLiterals = false;
}
In form text box show ( . . . ), exactly what I want. When my input is 123.123.123.123
everything is okay, but when I input 23 .1 .001.200
, the return value is 23 .1 .001.200
, but I need 23.1.1.200
. How can I remove spaces, and return the normal value? Is this possible or not?
For ip check i use ,and this is solution !
try
{
IPAddress IP = IPAddress.Parse("127.0.0.000");
MessageBox.Show(IP.ToString());
}
catch (FormatException)
{
MessageBox.Show("Wrong ip !");
}
Upvotes: 3
Views: 11531
Reputation: 44931
Why not just make life easier on yourself and create 4 separate data entry boxes? I personally always have difficulty with the single textbox approach if I type too quickly or need to back up.
Then you can validate each box for valid data as the user leaves it to ensure that they don't enter an incorrect value.
And if you have access to a numeric editing text box, you could even set min and max values (or you could implement this yourself).
Upvotes: 3
Reputation: 4778
Yes, it's possible, take a look on MaskedTextBox.Mask Property, as per msdn
9 - Digit or space, optional.
Try to play with mask
Upvotes: 1
Reputation: 7891
You can just strip out the spaces when you access the Text property, e.g.
maskedTextBox1.Text.Replace(" ", "");
Upvotes: 2
Reputation: 28970
try with this code
var input = "009.009.009.900";
var result = input.Trim();
you can also use these function in the same domain
String.Trim
String.TrimEnd
String.TrimStart
String.Remove
Upvotes: 2