Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2008, 01:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Regular Expression and RegEx Obj.

I am trying to verify that a textbox contains nothing but A-Z, a-z and 0-9.

I tried
Code:
    Dim RegExObj As New _
        System.Text.RegularExpressions.Regex("^A-Za-z0-9") 

    MsgBox("Match: " & RegExObj.IsMatch(TxtBx.Text))
But this didn't really work for me.

With "abc" I got False. (Perfect.) With abc% I got False. (No good.)

There is no shortage of examples for how to do everything except what it is that I want to do (as usual)...
 
Old August 1st, 2008, 02:53 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Try this:

Dim RegExObj As New _
        System.Text.RegularExpressions.Regex("[^A-Za-z0-9]")

The ^ character at the beginning of the expression means "start of text". There is no "grouping" of the characters implied. So your expression was really looking for the *LITERAL STRING*
     A-Za-z0-9
to start the text. In other words
     "A-Za-z0-9 zambonis rule"
would pass. But you would need those first 9 characters *exactly* as is to pass.

It's only when you use the character grouper [...] that the ^ takes on the meaning of "NOT" (or, as I like to think of it, [^xyz] means "any EXCEPT xyz").
 
Old August 1st, 2008, 04:03 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Thanks; that did the trick.

These Regular Expressions are mindbenders.





Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression MunishBhatia ASP.NET 2.0 Professional 5 May 22nd, 2007 07:59 AM
REGULAR EXPRESSION pallone Javascript How-To 0 September 5th, 2006 06:52 AM
Regular Expression NewToXSL ASP.NET 1.0 and 1.1 Basics 1 June 13th, 2006 02:52 PM
Regular Expression Help Hadware .NET Web Services 3 November 4th, 2003 10:51 AM
help in regular expression diby Beginning PHP 1 September 17th, 2003 12:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.