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
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    whats the regex for this express ??

    Knock Knock
    Help again..
    Whats the regex for the format like

    883 02 12313545

    or

    883-02-12313545

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    3 numbers:
    [0-9]{3}

    a dash or a space:
    [- ]

    2 numbers:
    [0-9]{2}

    a dash or a space:
    [- ]

    8 numbers:
    [0-9]{8}

    so together:
    /[0-9]{3}[- ][0-9]{2}[- ][0-9]{8}/

    should do it
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Better to put the ^ and $ in to pass ONLY this pattern of numbers (and not e.g. abc 123 12 12345678 xyz)

    /^[0-9]{3}[- ][0-9]{2}[- ][0-9]{8}$/

    If you wish you can make the hyphens and/or spaces optional with

    /^[0-9]{3}[- ]?[0-9]{2}[- ]?[0-9]{8}$/


  •  

    Posting Permissions

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