473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Validating Royal Mail shipping with vb.net and regular expressions

I needed to use a regular expression to validate the shipping code that
was/is scanned by my application.

I use a windows (winform) application in Vb.net. I did it by creating
a function to handle the validation, and return true or false depending
on the value it received (which is just input from a scanner).
Make sure to import system.text.regularexpressions

Private Function ValidWaybill(ByRef strWaybill As String) As Boolean

If Regex.IsMatch(strWaybill, "^([A-Z]{2})([
]{1})([0-9]{4})([ ]{1})([0-9]{4})([ ]{1})([0-9]{1})([A-Z]{2})$") = True
Then
ValidWaybill = True
Else
ValidWaybill = False
End If

End Function

This works for me, at least it seems to.
The format of the value I need to validate is like this:

"AA 0000 0000 0AA"

So I made an expression that looks for two capital letters, followed by
a space. Next is two sets of 4 digit numbers, followed by spaces.
Last is one number, followed by two capital letters.

In my production code, the expression is stored in an XML file, and
this function reads it when it runs. This way, if I made a mistake, I
can fix it without re-compiling.

Hope this is usefull for someone!

Ciao.

Idletask

Nov 21 '05 #1
2 1833
Hi,

RegexLib.com has plenty of examples of regular expressions. I
believe this the pattern you are looking for.

http://www.regexlib.com/REDetails.aspx?regexp_id=583

Ken
------------------
<id******@msn.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I needed to use a regular expression to validate the shipping code that
was/is scanned by my application.

I use a windows (winform) application in Vb.net. I did it by creating
a function to handle the validation, and return true or false depending
on the value it received (which is just input from a scanner).
Make sure to import system.text.regularexpressions

Private Function ValidWaybill(ByRef strWaybill As String) As Boolean

If Regex.IsMatch(strWaybill, "^([A-Z]{2})([
]{1})([0-9]{4})([ ]{1})([0-9]{4})([ ]{1})([0-9]{1})([A-Z]{2})$") = True
Then
ValidWaybill = True
Else
ValidWaybill = False
End If

End Function

This works for me, at least it seems to.
The format of the value I need to validate is like this:

"AA 0000 0000 0AA"

So I made an expression that looks for two capital letters, followed by
a space. Next is two sets of 4 digit numbers, followed by spaces.
Last is one number, followed by two capital letters.

In my production code, the expression is stored in an XML file, and
this function reads it when it runs. This way, if I made a mistake, I
can fix it without re-compiling.

Hope this is usefull for someone!

Ciao.

Idletask
Nov 21 '05 #2
Hi-
thanks for that link. I didn't know about that website. I think I
have the pattern I need though. I am not an expert with regular
expressions, but that pattern looks a little different than what I
need. I will compare this to what I came up and and see what works
better.

Thanks again!

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: UndoMiel | last post by:
Hi, I am looking for a way to validate IP addresses using XML Schemas. The following is what i used: <xsd:simpleType name="IPType"> <xsd:restriction base="xsd:string"> <xsd:pattern...
7
by: monomaniac21 | last post by:
Hi guys! Can anyone tell me how you can perform validation on a string variable in PHP so that you can check if a specific character is contained within the string. The reason for this is i am...
2
by: charleswesley | last post by:
I find myself regularly needing to validate user input as either a) numeric only or b) valid email address format (user@domain.tld) I am assuming that there are regular expressions that can be...
1
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address...
4
by: SAL | last post by:
I am using a RegularExpressionValidator control on my ASP page, and I have the ValidationExpression property set to "Internet E-mail Address". The email address is valiated when the user puts in a...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
10
by: venugopal.sjce | last post by:
Hi Friends, I'm constructing a regular expression for validating an expression which looks as any of the following forms: 1. =4*++2 OR 2. =Sum()*6 Some of the samples I have constructed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.