Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 920517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:43:39+00:00 2026-05-15T18:43:39+00:00

i’m developing a WPF (.NET 3.5) application where i need to validate a textbox

  • 0

i’m developing a WPF (.NET 3.5) application where i need to validate atextbox with a regular expression to match Empty textbox or text like 02145 or 05145 or 02145,05879,02445. the expression i use is ^(0(2|5)[0-9]{3})?((,0(2|5)[0-9]{3})*?)$.

It almost works just that i won’t let me have empty textbox. here is some code

<Window.Resources>
    <data:Message x:Key="message"/>
    <Style x:Key="validButton" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" >
        <Setter Property="IsEnabled" Value="False"/>
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <!-- ......-->
                    <Condition Binding="{Binding ElementName=txtNumbers, Path=(Validation.HasError)}" Value="false"/>
                </MultiDataTrigger.Conditions>
                <Setter Property="IsEnabled" Value="True" />
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>

<TextBox Height="23" Margin="-194.5,-88,-195.5,0" Name="txtNumbers" VerticalAlignment="Top" Style="{StaticResource txtboxerrors}">
                        <TextBox.Text>
                            <Binding Path="Numbers" Source="{StaticResource message}" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <ExceptionValidationRule />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
 </TextBox>
<Button Height="23" Margin="0,0,-81,-189" Name="btnSendSMS" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" Click="btnSubmit_Click" Style="{StaticResource validButton}">Submit</Button>

And Class used for validation is below

class Message :IDataErrorInfo
{
    //...
    private string numbers;



    public string this[string columnName]
    {
        get
        {
            string result = null;
            //.....
            if (columnName == "Numbers")
            {
//multicellRegex has the ^(0(2|5)[0-9]{3})?((,0(2|5)[0-9]{3})*?)$ expression                 if(!Util.ValidateRegexPatern(Properties.Resources.multicellRegex,this.numbers))
                {
                    result = "Number not in the correct format.try 020xx or 05xxx,026xx";
                }
            }


            return result;
        }
    }

    public string Error
    {
        get { return  null; }
    }

   //.....
        public string Numbers
        {
          get { return numbers; }
          set { numbers = value; }
        }


}

this works well but then the submit button won’t be active unless i type one or more numbers in the txtNumbers textbox.I just want it to allow empty textbox.
How should i achieve that? Thanks for readking

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:43:40+00:00Added an answer on May 15, 2026 at 6:43 pm

    You should make the entire pattern optional, not the separate parts, or it will think that ,02000 is a valid entry.

    As each number has a specific length, you don’t need to make the match non-greedy (using *?).

    ^((0[25]\d{3})(,0[25]\d{3})*)?$.
    

    Allowing for whitespace around the numbers would be:

    ^\s*((0[25]\d{3})(\s*,\s*0[25]\d{3})*)?\s*$.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.