using Regular Expression in Javascript - how to validate a string

Discussion in 'JavaScript' started by maximusdm, Mar 18, 2010.

  1. #1
    hi there

    I am new to regular expressions and was looking for a javascript code which would validate a string which should contain 40 characteres from a-z or 0-9, for instance:

    2ec04e0ae92046ec02cfss1d0306b074d9270580

    Thank you
    M
     
    maximusdm, Mar 18, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    
    var str = '2ec04e0ae92046ec02cfss1d0306b074d9270580';
    if (/^[a-z0-9]{40}$/i.test(str)) alert('OK');
    
    Code (markup):
    Regards :)
     
    koko5, Mar 18, 2010 IP
  3. maximusdm

    maximusdm Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you!
     
    maximusdm, Mar 23, 2010 IP