file ext

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ogo796
    New Member
    • Jan 2008
    • 44

    file ext

    hi guys
    new in javascript so my question is i wanna validate the file extension

    like this
    namewww.jpg
    ojfgt.rtf
    hfyrkeode.pdf

    so my problem is i don't know the length of the file name so i wanna validate base file.ext

    var f = fld;
    var t = f.substring(-4)
    so i am wondering if this is the right syntax of substring
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use indexOf or lastIndexOf to get the position of the dot and then use that with substring.

    Comment

    • hirak1984
      Contributor
      • Jan 2007
      • 316

      #3
      Originally posted by acoder
      Use indexOf or lastIndexOf to get the position of the dot and then use that with substring.
      you can use the "split" method of javascript.
      it has syntax same as the "String".split( "String") in Java.
      Google for it

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by hirak1984
        you can use the "split" method of javascript.
        it has syntax same as the "String".split( "String") in Java.
        Google for it
        Yes, that's also a possibility. Here is a useful reference.

        Comment

        Working...