?
Solved

URGENT: Easy Regex Question

Posted on 2004-04-07
3
Medium Priority
?
291 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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