Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

c# - How to validate a UK postcode

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...