Javascript validation for wildcard in string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gayuvinu
    New Member
    • Sep 2009
    • 2

    Javascript validation for wildcard in string

    Hi,
    I am new to javascript, I need your help in javascript validation of a string.
    string of length 6,
    last 4 characters can be padded with "8" while entering.
    valid strings are
    ZJJL74
    ZJJL7*
    ZJJL**
    ZJJ***
    ZJ****

    Invalid strings are
    ZJ*L74
    ZJJ*7*
    *JJL**
    Z*****
    *****4
    this means * cannot be entered in the middle,
    it can be entered only at the end maximum up to last 4 characters.
    please provide the solution ASAP, will be very grateful
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    try using indexOf() function that will give you the solution what you are looking for...

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • gayuvinu
      New Member
      • Sep 2009
      • 2

      #3
      can you please give the function with an example

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        why is everyone always wanting the code?

        you could also try an RegExp. (you’ll probably need the look-ahead and/or look-before groups (?=, ?!, ?<=, ?<!))

        Comment

        Working...