Help on Regular Expressions

  • Thread starter Thread starter kieran
  • Start date Start date
K

kieran

Hi,

I am unfamilar with Regular Expressions and have been trying to get a
regular expression for a car registration field on a form. What i need
the expression to do is to not allow spaces or dashes i.e. '-'.

For example we have car regs that must be in the form of 01D21, but
some users enter 01 D 21 or 01-D-21.

Any help, greatly appreciated.
 
kieran said:
I am unfamilar with Regular Expressions and have been trying to get a
regular expression for a car registration field on a form. What i need
the expression to do is to not allow spaces or dashes i.e. '-'.

For example we have car regs that must be in the form of 01D21, but
some users enter 01 D 21 or 01-D-21.

\\\
Imports System.Text.RegularExpressions
..
..
..
MsgBox(Regex.IsMatch("12D01", "^\d\d[A-Z]\d\d$"))
MsgBox(Regex.IsMatch("12-D 01", "^\d\d[A-Z]\d\d$"))
///
 
kieran said:
I am unfamilar with Regular Expressions and have been trying to get a
regular expression for a car registration field on a form. What i
need the expression to do is to not allow spaces or dashes i.e. '-'.

For example we have car regs that must be in the form of 01D21, but
some users enter 01 D 21 or 01-D-21.

Any help, greatly appreciated.

How about using Replace to remove spaces and dashes?

It's nicer for the program to understand user input than for the user to
have to conform to some arbitrary restriction on what they can input.

Andrew
 
cheers Herfried and Andrew for your help.

both work great...i forgot all about Replace...it'll be much more
usability friendly.

cheers.
 
kieran said:
cheers Herfried and Andrew for your help.

both work great...i forgot all about Replace...it'll be much more
usability friendly.

In addition to that, you could use a masked edit box (available out of the
box in .NET 2.0) which allows the user to enter data in a certain format, or
you could use an ErrorProvider component to make the user aware of malformed
input when input validation is performed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top