#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    13
    Rep Power
    0

    regex in javascript


    i want to allow input in the form of letters, numbers, hyphens and underscores only in any order or combination. i looked at a bunch of examples online, and i thought this would work, however it still allows invalid data.

    // should return true if value is valid?
    boolvar = /[A-Za-z0-9-_]/.test(value);

    //or is it...
    boolvar = /[A-Z][a-z][0-9]-_/.test(value);

    thanks.

    mrGarretson
  2. #2
  3. No Profile Picture
    CF sMod
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Maine, USA (a.k.a. Boonies)
    Posts
    242
    Rep Power
    14
    if (!/[^\w-]/.test(value))
    Jason Contact Me
    Super moderator @ CodingForums
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    13
    Rep Power
    0
    thanks man.

IMN logo majestic logo threadwatch logo seochat tools logo