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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:04+00:00 2026-05-27T18:48:04+00:00

I am looking for a regular expression to check names. I have searched the

  • 0

I am looking for a regular expression to check names. I have searched the net and also used the suggestion that were given me by StackOverflow while posting this question.

I also know it’s possible in stages, but I’m looking for a regex-1-liner to keep my code clean, simple and most important: fast.

What do I need:
A regular expression that checks names of people while they are registering to my site. I want to allow names as:

  • Name
  • Name surename
  • Name O’brian
  • Name surename secondarysurname
  • Name surename-surnametwo
  • N. Surename

But I don’t want to allow names as:

  • Name (double spacebar)
  • Name — surename (double minus)
  • Name–‘ (just bullshit)

Well, I think you understand what I mean and what I don’t want to allow.

I only want to use a-zA-Z and – . ‘
I think that’s the only thing I need to allow. The – . ‘ signs can only be used once between or after a word. Since a name like ‘name O”Brian’ does not exist.

But a name like ‘Name surename secondary-thirdsurname’ should be allowed. So one spacebar and one minus sign.

I came up with several regex’ using http://public.kvalley.com/regex/regex.asp and other regex programs. But I’m just a noob with regex’.

I hope somebody knows a lot about regular expressions and is willing to help me. Because at the moment.. I’m stuck 🙁

Thanks in advance,

Jelmer

ps. If you have any questions regarding my question. Please ask them because I’d really like to have your help!

  • 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-27T18:48:05+00:00Added an answer on May 27, 2026 at 6:48 pm

    A general rule of thumb that applies to many aspects of coding, but especially to regex design, is, your code can be:

    1. Simple
    2. Clean
    3. Fast

    Pick two.

    In addition to that, I guarantee that a one-liner this complex will never be clean. Break it up into regex variables and comment it liberally. Later on, you’ll be thankful that you did! While you’re at it, turn it into a generic name validator class that you can reuse. While Perl can be quite munged by experts into something totally unholy, it’s beauty often comes out when we follow the same laws of politeness and cleanliness that we follow in other, more structured languages.

    TL;DR: Don’t make it a one-liner. Please.

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

Sidebar

Related Questions

I am looking for a regular expression for c# asp.net 3.5 that will fail
Hi I'm looking a regular expression that will change this: [check out this URL!](http://www.reallycoolURL.com)
I'm looking for a regular expression library in .Net that supports lazy evaluation. Note:
I'm looking for a regular expression that will match all strings EXCEPT those that
I am looking for a regular expression that will test for matches against a
I have been looking for a regular expression with Google for an hour or
Given a regular expression, I'm looking for a package which will dynamically generate the
I'm looking for a .NET regular expression extract all the URLs from a webpage
I'm looking for a regular expression that checks whether a string contains 2 specific
I'm looking for a regular expression to use with an ASP.NET Regular Expression Validator

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.