-2

I am new to programming.

I am creating a windows form application in Visual Studio 2013

I am trying to create a textbox into which the user enters there postcode.

I need it to accept all possible UK postcode formats, using upper and/or lower case letters as well as with/without space

So far I have the following code

namespace Moondog_odering_system
{
    public partial class CustomerDetails : Form
    {
        public CustomerDetails()
        {
            InitializeComponent();
        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {
           "(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))";         
        }
    }
}       

This is coming up with the following Error which I cannot work out a solution for

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

This is assigned to line 21 which is the text above I have put in itallics

When you mouse over this code it says it is class System.String

Can anyone please provide a solution

Tomas Pastircak
  • 2,867
  • 16
  • 28
user3511106
  • 21
  • 1
  • 4

2 Answers2

0

Have a look on the below links to get your problem solved.

to apply regex e-mail validation on windows form

and for UK regex http://regexlib.com/REDetails.aspx?regexp_id=2484&AspxAutoDetectCookieSupport=1

Community
  • 1
  • 1
Amnesh Goel
  • 2,617
  • 3
  • 28
  • 47
0

In your method

private void textBox11_TextChanged(object sender, EventArgs e)
{
    "(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))";         
}

you have something which is not a statement. The error message has said this much. It also tells you what is acceptable as a statement.

The solution to your question is to re-read the book from which you are learning to program, look for similar constructs, and apply them.

ClickRick
  • 1,553
  • 2
  • 17
  • 37