[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

URGENT: Easy Regex Question

Posted on 2004-04-07
4
Medium Priority
?
192 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
  • 2
  • 2
4 Comments
 
LVL 5

Author Comment

by:jjacksn
ID: 10780163
I would like to use hyphen as well.
0
 
LVL 12

Accepted Solution

by:
dfiala13 earned 2000 total points
ID: 10780316
Try this, you need to include all the valid characters in the brackets, and the period is a special character you have to escape it... (as is the hyphen)

[^A-Za-z0-9\.\-]
0
 
LVL 5

Author Comment

by:jjacksn
ID: 10780337
for future reference, how do I undo the negation?  
0
 
LVL 12

Expert Comment

by:dfiala13
ID: 10780355
pop out the ^

[A-Za-z0-9\.\-]

will match any string that has one of the characters in brackets
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

830 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