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 6744987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:00+00:00 2026-05-26T12:09:00+00:00

I have to check user input to make sure name, last name (etc…) are

  • 0

I have to check user input to make sure name, last name (etc…) are entered correctly and are valid. I have to build a regexp that check if a user enters repeated letters in the first name , last name etc…

Example:

  • AAAron = bad because of the 3 A’s
  • AAron = good
  • Hannah = Good
  • Hannnah = bad because of the 3 N’s

Is there a PHP regular expression to catch these cases? (I have a basic regexp knowledge but this is too much for me)

EDIT:
This should Allow numbers as well: David 3 or III

Thanks

  • 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-05-26T12:09:00+00:00Added an answer on May 26, 2026 at 12:09 pm

    You can use back reference for that purpose.

    preg_match('/(\w)(\1+)/', $subject, $matches);
    print_r($matches);
    

    the \1 means repeat the first capture so in that case \w.

    In the case of your example, I don’t think using regular expression would be the best solution, why don’t you just count the number of instance of any characters?

    i.e.

    $charCountArray = array();
    foreach ($name as $char) {
        $charCountArray[$char]++;
    }
    

    back reference is an advanced feature, luckily the PCRE functions supports it.

    Note: preg_match would match only one sequence, if you need to know all the matches please use preg_match_all

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

Sidebar

Related Questions

I have a user model on which I check to make sure that the
I have the following: <input id=user_profile_pic name=user[profile_pic] type=file> On the server I check to
I have this HTML field: <input type=text name=userInput id=userInput> I want to make sure
I usually have to check things like: if ['Bob','Mary','John'].include? @user.name Is there a way
i have a data validation class method where i check the user input before
preg_match(/^([0-9a-zA-Z])+$/, $newvalue) I have the above code for preg_match, to check if user input
I have a log function on my admin panel that checks user input for
I have a form which have many check boxes in it. User will check
I want to have functionality on my application that lets a user check off
I have about 20 check boxes. When the user selects these and then uses

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.