Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:18:27+00:00 2026-06-05T17:18:27+00:00

<?php $string = ‘user34567’; if(preg_match(‘/user(^[0-9]{1,8}+$)/’, $string)){ echo 1; } ?> I want to check

  • 0
<?php

    $string = 'user34567';

            if(preg_match('/user(^[0-9]{1,8}+$)/', $string)){
                echo 1;
            }

?>

I want to check if the string have the word user follows by number that can be 8 symbols max.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:18:29+00:00Added an answer on June 5, 2026 at 5:18 pm

    You’re very close actually:

    if(preg_match('/^user[0-9]{1,8}$/', $string)){
    

    The anchor for “must match at start of string” should be all the way in front, followed by the “user” literal; then you specify the character set [0-9] and multiplier {1,8}. Finally, you end off with the “must match at end of string” anchor.

    A few comments on your original expression:

    1. The ^ matches the start of a string, so writing it anywhere else inside this expression but the beginning will not yield the expected results
    2. The + is a multiplier; {1,8} is one too, but only one multiplier can be used after an expression
    3. Unless you’re intending to use the numbers that you found in the expression, you don’t need parentheses.

    Btw, instead of [0-9] you could also use \d. It’s an automatic character group that shortens the regular expression, though this particular one doesn’t save all too many characters 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Excuse the terrible question title. I have this PHP string and want to check
I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
I have a php script that is reading a file in (file_get_contents). I want
How can I check if a PHP string contains any white space? I want
i have simple form that uploads image to server and returns php string containing
This string has a php echo. I must have messed something up because it
Is there a PHP string function that transforms a multi-line string into a single-line
I'm echoing a php string variable into html <span class=title_resource> <?php echo $titulo; ?>
Possible Duplicate: PHP Get end string on url between / and / I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.