Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post

    Regular Expression

    Dear experts

    I have following codes

    Var re=/(\d){4}-(\d){7}/;

    When I test this string
    0300-685706263

    It says TRUE

    But I validate this string exactly

    0300-6857062

    Please help

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Not sure that understand you correctly. Maybe this will help:
    Code:
    var re=/^(\d){4}\-(\d){7}$/;
    I am still learning English

  • Users who have thanked Amphiluke for this post:

    tqmd1 (01-21-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,729
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by tqmd1 View Post
    Dear experts

    I have following codes

    Var re=/(\d){4}-(\d){7}/;

    When I test this string
    0300-685706263

    It says TRUE

    But I validate this string exactly

    0300-6857062

    Please help
    0300-685706263 returns true because it matches your pattern. What you want is to match your pattern and nothing but. As amphiluke has shown you.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    tqmd1 (01-21-2012)


  •  

    Posting Permissions

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