www.webdeveloper.com
Results 1 to 4 of 4

Thread: Reg expression validation using test() and search()

  1. #1
    Join Date
    Dec 2010
    Posts
    40

    Reg expression validation using test() and search()

    Is there difference in using regexp.test(string) or str.search(regex)? Getting difrnt results when I use one vs to other.

    I use sample: http://www.tek-tips.com/viewthread.c...264340&page=10. For input value "tes?t.txt" I get different output when using search method vs test method.

    help?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    rx.test(string) returns true or false, depending on whether there is a match

    string.search(rx) returns the index of the first character of a match, or -1

  3. #3
    Join Date
    Dec 2010
    Posts
    40
    thnx, got that in theory. but for this example, i meantioned, outpt is nt right. doesnot behave as per definition.

  4. #4
    Join Date
    Dec 2010
    Posts
    40
    Any suggestions.....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles