Results 1 to 6 of 6

Thread: Alphanumeric

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Alphanumeric

    What is the text you are searching?

  3. #3
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    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

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Alphanumeric

    Quote 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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Alphanumeric

    Code:
    ^[a-zA-Z0-9]+$
    + 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
  •  



Click Here to Expand Forum to Full Width