Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

URGENT: Easy Regex Question

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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