Fom Validation

Discussion in 'JavaScript' started by 2mk_atspace, Dec 6, 2005.

  1. #1
    var name=/[a-zA-Z]{5,30}/;

    I use this script to validate my form but, when i enter more than 30 character, it's still valid, why ?
     
    2mk_atspace, Dec 6, 2005 IP
  2. Michau

    Michau Well-Known Member

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Because this regular expression looks for a SUBSTRING in the macthed string. So if it has 31 characters, there is surealy a substring that has 30 characters.

    You probably wanted to write this:
    /^[a-zA-Z]{5,30}$/

    This will do what you want.
     
    Michau, Dec 6, 2005 IP