Solved

URGENT: Easy Regex Question

Posted on 2004-04-07
3
290 Views
Last Modified: 2010-04-15
I'm missing something here,  I only want to allow alphanumeric characters and the period.  i have the following code

Regex regex = new Regex("[^[a-z][A-Z][0-9].]");
if(regex.IsMatch(txtName.Text) == true)

Do I need a carrot before each of those sub groups?  

(the code is not working properly).
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:eric_duncan
ID: 10780716
Try this instead, it should do what you want:

Regex regex = new Regex("^[a-zA-Z0-9.]+$");


0
 
LVL 2

Accepted Solution

by:
eric_duncan earned 500 total points
ID: 10780781
To explain further, tou need to group all of the characters you are looking for into a single group rather than creating three consecutive groups because the regex parser will process this as looking for 3 consecutive characters rather than a single character that is a member of all three groups.

In plain english, your old regex does this:

First, match any character not in "[a-z",
followed by any character in "A-Z",
followed by any character in "0-9",
followed by any character,
followed by ].

The new one supplied above does this:

First, start at the beginning of the string,
then match any character in "a-zA-Z0-9." and continue doing this until the end of the string is reached.

Does this help?

Eric
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10780886
Regex regex = new Regex("[a-zA-Z0-9.]+");
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question