|
-
Mar 14th, 2007, 06:16 AM
#1
Thread Starter
PowerPoster
Alphanumeric
In C#, what is the Regex to check for alphanumeric characters? Everytime I try the expression below, it returns false!
^[a-zA-Z0-9]$
removing the ^ and $ doesnt work entirely either.
-
Mar 14th, 2007, 06:20 AM
#2
Re: Alphanumeric
What is the text you are searching?
-
Mar 14th, 2007, 08:19 AM
#3
Hyperactive Member
Re: Alphanumeric
Don't forget to put a pipe-delimiter between them in the square brackets. Example, "^[a-z|A-Z|0-9]$".
Currently Using: VS 2005 Professional
-
Mar 14th, 2007, 08:23 AM
#4
Re: Alphanumeric
 Originally Posted by tacoman667
Don't forget to put a pipe-delimiter between them in the square brackets. Example, "^[a-z|A-Z|0-9]$".
Not in a character class.
-
Mar 14th, 2007, 08:30 AM
#5
Thread Starter
PowerPoster
Re: Alphanumeric
Thanks.
Well I got it to work to use 2 different patterns:
[a-zA-Z]
[0-9]
the text would be anything entered at all, such as a password. Want to check to see that it DOES contain at least 1 letter and number in the string given to this method. I would rather have it done in 1 go rather than calling it twice with seperate REGEX pattern
-
Mar 15th, 2007, 07:30 AM
#6
Re: Alphanumeric
+ means "at least one"
alternatively
Code:
string myregex = @"^(\d|\w)+$";
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|