Home > Archive > Visual Basic Syntax > April 2005 > Regular expressions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Regular expressions
|
|
|
| Hi all.
Can someone please show how to use Regular expressions to validate that the
input string is composed only from a-z and 0-9 ?
TIA
Guy
| |
| Rick Rothstein 2005-04-26, 4:04 am |
| > Can someone please show how to use Regular expressions to
> validate that the input string is composed only from a-z and 0-9 ?
Are you using VB6 or lower? If so, you don't need to use Regular
Expressions... you can use the Like operator.
If Not YourTextString Like "*[!a-z0-9]*" Then
'
' Your text is composed only of
' lower case letters and digits.
'
End If
If you want upper case letters too, then change the IF statement to this
If Not YourTextString Like "*[!a-zA-Z0-9]*" Then
On the other hand, if you are using a version of VB.NET, then consider
this...
Almost everybody in this newsgroup is using VB6 or lower. While you may
get a stray answer to VB.NET (including VB2003 and VB2005 which has
dropped .NET from its name) questions here, you should ask them in
newsgroups devoted exclusively to .NET programming. Look for newsgroups
with either the word "dotnet" or "vsnet" in their name.
For the microsoft news server, try these newsgroups for Visual Basic
..NET related questions...
microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data
And these for more general .NET questions
microsoft.public.dotnet.general
microsoft.public.vsnet.general
Note: There are many other .NET newgroups (use the first three "fields"
from the last two as templates when searching for them), but the above
ones should get you started.
Rick - MVP
| |
|
| AHHHHHHHHHHHHHHHHH
Just learned something new today :)
Thank you Rick
Guy
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:O2FSbYiSFHA.1096@tk2msftngp13.phx.gbl...
>
> Are you using VB6 or lower? If so, you don't need to use Regular
> Expressions... you can use the Like operator.
>
> If Not YourTextString Like "*[!a-z0-9]*" Then
> '
> ' Your text is composed only of
> ' lower case letters and digits.
> '
> End If
>
> If you want upper case letters too, then change the IF statement to this
>
> If Not YourTextString Like "*[!a-zA-Z0-9]*" Then
>
> On the other hand, if you are using a version of VB.NET, then consider
> this...
>
> Almost everybody in this newsgroup is using VB6 or lower. While you may
> get a stray answer to VB.NET (including VB2003 and VB2005 which has
> dropped .NET from its name) questions here, you should ask them in
> newsgroups devoted exclusively to .NET programming. Look for newsgroups
> with either the word "dotnet" or "vsnet" in their name.
>
> For the microsoft news server, try these newsgroups for Visual Basic
> .NET related questions...
>
> microsoft.public.dotnet.languages.vb
> microsoft.public.dotnet.languages.vb.upgrade
> microsoft.public.dotnet.languages.vb.controls
> microsoft.public.dotnet.languages.vb.data
>
> And these for more general .NET questions
>
> microsoft.public.dotnet.general
> microsoft.public.vsnet.general
>
> Note: There are many other .NET newgroups (use the first three "fields"
> from the last two as templates when searching for them), but the above
> ones should get you started.
>
> Rick - MVP
>
| |
|
|
| Dick Grier 2005-04-26, 8:59 pm |
| Hi Chris,
I've thought (silently before now), "Using Regular Expressions in VB is like
'casting pearl(s) before swine.'"
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
| |
|
| I used Regular Expressions in a recent release of an application of mine. I
am amazed at the power and flexibility (if you can figure out the
expressions and syntax on more complicated searches)...
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:%23uu2aQpSFHA.3636@TK2MSFTNGP14.phx.gbl...
> Hi Chris,
>
> I've thought (silently before now), "Using Regular Expressions in VB is
like
> 'casting pearl(s) before swine.'"
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>
| |
| Rick Rothstein 2005-04-27, 4:00 am |
| > I used Regular Expressions in a recent release of an application of
mine. I
> am amazed at the power and flexibility (if you can figure out the
> expressions and syntax on more complicated searches)...
The most fun is trying to read them back, say, a month from now and
figure out how it works. I used to do a lot of regular expression
development back in the late 1980's and early 1990's on the UNIX machine
we had at work. They were fun to develop (how could then not be, they
were one-liners<g> ), but reading them back even the next day was really
a XXXXX. They were so cryptic... I loved them!
Rick
| |
|
| Sometimes a day later causes confusion.
You must have been in all your glory with the one liner-ness (made up word)
of a regular expression
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:ubCAnktSFHA.1148@tk2msftngp13.phx.gbl...
> mine. I
>
> The most fun is trying to read them back, say, a month from now and
> figure out how it works. I used to do a lot of regular expression
> development back in the late 1980's and early 1990's on the UNIX machine
> we had at work. They were fun to develop (how could then not be, they
> were one-liners<g> ), but reading them back even the next day was really
> a XXXXX. They were so cryptic... I loved them!
>
> Rick
>
| |
| Rick Rothstein 2005-04-27, 4:00 am |
| > You must have been in all your glory with the one liner-ness
> (made up word) of a regular expression
You cannot even begin to imagine... <vbg>
Rick
| |
|
| Can someone please show more exaple of "like" operator?
How do I check email addresses with "like" ?
how do I use "like" to validate a minimum/maximum digits used ?
Guy
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%236V8xVuSFHA.2256@tk2msftngp13.phx.gbl...
>
> You cannot even begin to imagine... <vbg>
>
> Rick
| |
| Rick Rothstein 2005-04-27, 4:01 pm |
| > Can someone please show more exaple of "like" operator?
> How do I check email addresses with "like" ?
> how do I use "like" to validate a minimum/maximum digits used ?
Think of Like as an infant cousin of Regular Expressions... it can't
come close to doing everything that Regular Expressions can do (although
it might be possible to get close using multiple Like tests coupled with
other code). However, to do properly be able to do either, one must
define the problem that one wants to solve. When you say "check email
addresses", would you be satisfied with this format:
something@some.place
or do you want a full out test for all legitimate characters in their
only possible positions? If the latter, well, I've seen several
interpretations of that many of which differ from each other. I'm not
sure anyone actually "knows" a Regular Expression encompassing all of
the legitimate forms an email address can have. On the other hand, we
can handle the former with a Like test or two. As for your "validate a
minimum or maximum digits used" question, I'm not exactly sure what you
are asking for; can you describe that one in some more detail?
Rick - MVP
| |
| Dick Grier 2005-04-27, 4:01 pm |
| Hi Chris,
[color=darkred]
I used Regular Expressions in a recent release of an application of mine. I
am amazed at the power and flexibility (if you can figure out the
expressions and syntax on more complicated searches)...
<<
Yeah, I know. I just hate them. So, I was trying to be funny (while
expressing my dislike). When you are in need, you will do (almost)
anything. And, Regular Expressions are a nice feature in, shudder, .NET.
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
| |
|
| True - There are cases where Regular Expressions are the only option. For
me it was that the application needed to have Regular Expression support to
compete with similar type applications...
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:uF0Sk$zSFHA.1896@TK2MSFTNGP14.phx.gbl...
> Hi Chris,
>
> I used Regular Expressions in a recent release of an application of mine.
I
> am amazed at the power and flexibility (if you can figure out the
> expressions and syntax on more complicated searches)...
> <<
>
> Yeah, I know. I just hate them. So, I was trying to be funny (while
> expressing my dislike). When you are in need, you will do (almost)
> anything. And, Regular Expressions are a nice feature in, shudder, .NET.
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>
|
|
|
|
|