0

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 okey,but when i in put 23 .1 .001.200 , , and return value 23 .1 .001.200 , but need, 23.1.1.200 . How can remove spaces , and return normal value ? Is this possible or not ?

3
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by ingus16
0

Why dont you use a normal TextBox control instead of MaskeTextBox?

In IP case, it would be a better option.

Anyway, if you would like to use MaskeTextBox, and if you wanna remove spaces use Replace method of string class:

            string input = "23 .1 .001.200";
            if (input.Contains(" "))
                input = input.Replace(" ", "");
0

You can remove spaces exactly like Mitja Bonca said. And you don't have to care about removing zeros - you can try to parse your IP address like that (based on Mitja Bonca's code):

string input = "23 .1 .001.200";
if (input.Contains(" "))
    input = input.Replace(" ", "");
IPAddress ipAddress;
if (IPAddress.TryParse(input, out ipAddress))
{
    //IP address has been parsed correctly
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.