Textbox validation for IP Address in WPF

16,747

Solution 1

You can easily implement this using Wpf binding validation rules or by using a custom masked textbox

Check these links for exactly what you are looking for

http://geekswithblogs.net/QuandaryPhase/archive/2008/12/17/wpf-masked-textbox.aspx

http://www.switchonthecode.com/tutorials/wpf-tutorial-binding-validation-rules

Hope it helps..

Solution 2

The following question link on StackOverflow contains a lot of pointers to MaskedTextBox implementation in WPF. You can use it to get IP Address input from user.

Where can I find a free masked TextBox in WPF?

Solution 3

Sounds like you're trying to implement a masked textbox, which is a textbox that auto-format data as the user types according to a specified pattern. Check this tutorial on how to implement this, since is not featured in WPF out-of-the-box: Masked TextBox in WPF

Solution 4

 <TextBox IsReadOnly="False" Name="txtIpAddress">
                            <TextBox.Text>
                                <Binding Path="IpAddress" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" >
                                    <Binding.ValidationRules>
                                        <Local:IPValidationRule />
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
Public class IPValidationRule: ValidationRule
    {
     public override ValidationResult Validate(object value,System.Globalization.CultureInfo cultureInfo)
    {
    if(value == Rejex.Match(your condtion)
    {
    return new ValidationResult(true, null);
    }
    else
    {               
     return new ValidationResult(false, "Invalid_Address");
    }
    }
    }
 
Share:
16,747

Related videos on Youtube

Kyu
Author by

Kyu

Updated on May 13, 2022

Comments

  • Kyu
    Kyu about 2 years

    I'm making a WPF Application using C#. I want to put validations on integers (0123456789 and ".") only.. The textbox is supposed to contain an IP address... So need to ensure that user key in their correct "IP Address" before they click on the "Submit" button... How can I achieve it?

    Thanks.

  • MarkusEgle
    MarkusEgle almost 5 years
    Answer is currently nearly useless as the link to the tutorial on progware.org is down.