www.webdeveloper.com
Results 1 to 5 of 5

Thread: regex returns false, when it should return true

  1. #1
    Join Date
    Apr 2010
    Posts
    26

    regex returns false, when it should return true

    Hey all,

    I have a regex here:

    Code:
    var NameValidator = { 
    
    first_middle_last_with_first_middle : function(txt){ 
    
    var regex = /^w{1,}\s\w{1}\s\w{1,}\s&W\s\w{1,}\s\w{1}$/ 
    alert(regex.test(txt)); 
    } 
    
    } 
    
    
    
    NameValidator.first_middle_last_with_first_middle('ROGELIO P DIAZ &W CLUADIA L'); 
    
    })()
    It alerts false. Why is the string failing? It should be matching.

    Thanks for response

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    The first problem I see is the first character is expected to be a lowercase 'w'.


    Q: I found this code...
    A: Then find its author.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I suspect you wanted to be (see the blue escape):
    Code:
    var regex = /^\w{1,}\s\w{1}\s\w{1,}\s&W\s\w{1,}\s\w{1}$/

  4. #4
    Join Date
    Apr 2010
    Posts
    26
    Quote Originally Posted by Kor View Post
    I suspect you wanted to be (see the blue escape):
    Code:
    var regex = /^\w{1,}\s\w{1}\s\w{1,}\s&W\s\w{1,}\s\w{1}$/
    yes, I missed the forward slash!

  5. #5
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by JohnMerlino View Post
    yes, I missed the forward slash!
    / = forward slash.
    \ = back slash.
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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