ASP: Regular Expressions

Discussion in 'C#' started by cancer10, Jul 7, 2008.

  1. #1
    HI,

    I need to make a function in ASP and regular expressions that would accept data only in A-Z, a-z, 0-9 only.


    Like:


    function db(data){
    
    'I need the coding here....
    
    }
    Code (markup):

    Plz help me


    thanx
     
    cancer10, Jul 7, 2008 IP
  2. helpbeam

    helpbeam Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This doesnt use regex but it will filter the characters

    function OnlyAZ123(data) as boolean

    'heres the characters it can contain
    CharsToMatch ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    x=0

    'assume its ok til we look at the characters
    CharsOK=True
    for x = 1 to len(data)
    'check them one at a time
    if instr(CharsToMatch,mid(data,x,1)) = 0 then
    CharsOK=False
    exit for
    end if
    next

    return CharsOK


    end function
     
    helpbeam, Jul 7, 2008 IP
  3. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So, in this list "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

    can I add other characters as well?


    Like, CharsToMatch ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\^/+_"


    or will it not work if i add those special chars??

    Thanx
     
    cancer10, Jul 7, 2008 IP
  4. VishalVasani

    VishalVasani Peon

    Messages:
    560
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,

    U can us following regular Expressions
    
    dim RExp : set RExp = new RegExp
    with RExp
    .Pattern = "^([0-9a-zA-Z])$"
    .IgnoreCase = True
    .Global = True
    end with
    Code (markup):
     
    VishalVasani, Jul 7, 2008 IP
  5. helpbeam

    helpbeam Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can add other characters to the ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 list
     
    helpbeam, Jul 7, 2008 IP