Thread: Regex name test

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Posts
    83
    Rep Power
    8

    Regex name test


    hi

    im trying to create a regex pattern for a name field. Basically, I want to throw an error only if the user types in certain strings



    !?<>


    otherwise, even if the field is empty, the field should be true.

    this is the pattern i created,but it does not seem to work if I have a empty space in the field:

    Code:
    return /^[a-zA-Z']{1,40}$/.test(str);
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    So you don't want ! ? < > in the field? Up to 40 characters?
    Code:
    /^[^!?<>]{1,40}$/
    That checks if it is valid (as opposed to checking if it's invalid).

IMN logo majestic logo threadwatch logo seochat tools logo