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 6 of 6
  1. #1
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts

    combine strlen with preg, help please

    Hi... i would be like to say thank you and grateful for someone who consider to help me...

    i want to change this code:

    PHP Code:
        function isPhoneValid() {
            
    // 5 digits number
     
    return ereg('^[0-9]${5}'$this->phone);
        } 
    with adding strlen.. so become >5 digit number...

    Regards,
    Last edited by mjs; 02-19-2010 at 05:13 AM. Reason: Resolved

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    return ctype_digit$this->phone ) && strlen$this->phone ) >= 5
    Last edited by kbluhm; 02-19-2010 at 05:51 AM.

  • Users who have thanked kbluhm for this post:

    mjs (02-18-2010)

  • #3
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Yes, this work fine... thank you n GBU bro, but how to mark this thread solved?
    Last edited by mjs; 02-18-2010 at 06:58 AM.

  • #4
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    or just

    PHP Code:
    return ereg('^[0-9]${5,}'$this->phone); 
    {5} means exactly five digits
    {5,10} means between 5 and 10 characters
    {5,} means 5 or more characters

    Incidentally I would think it should be '^[0-9]{5,}$' as $ indicates the end of the data and so should be at the end of the pattern, may work the other way but seems less correct to me.

    Caveat: I always use PCRE regex functions preg_ rather than ereg_ but assuming ereg_ supports {5} it should support {5,} as well.

    HTH,

    Dai

  • #5
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    If you want to use preg_match(), it would be:
    PHP Code:
    return ( bool ) preg_match'/^\d{5,}$/'$this->phone ); 
    And to mark the topic as resolved, I believe you'd edit it, and next to the subject line there should be a select-menu marked `Prefix`.
    Last edited by kbluhm; 02-19-2010 at 05:50 AM.

  • #6
    mjs
    mjs is offline
    New Coder
    Join Date
    Jan 2010
    Posts
    97
    Thanks
    17
    Thanked 0 Times in 0 Posts
    oh... that's several ways to solved this..


  •  

    Posting Permissions

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