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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:04:30+00:00 2026-06-17T19:04:30+00:00

I am looking to create Regex for the first name which can allow all

  • 0

I am looking to create Regex for the first name which can allow all the special characters except @()&, I am trying to implement it in PHP i tried something like
/^[^0-9\@\(\)\&][a-zA-Z\s]*$/ but its not validating properly .

  • 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-17T19:04:31+00:00Added an answer on June 17, 2026 at 7:04 pm

    If your intention was to allow special characters (other than those four) anywhere in the string, then your pattern is wrong.

    I’ll break down your pattern to walk you through what it does:

    • ^ – The match must begin at the start of a line (or entire string).
    • [^0-9\@\(\)\&] – Match any single character which is not a number, an @, a parenthesis, or an ampersand. I’m pretty sure the slashes here are superfluous, by the way. The ones before the @ and & characters almost certainly are, since those characters aren’t ever special inside regexes. The ones before the ( and ) might be needed, since those characters are the subpattern delimiters, but I think they’re still unneeded here since they’re inside a character class.
    • [a-zA-Z\s]* – Match any lower or uppercase character between A and Z, or any whitespace character, like a space (this is what \s does). The * means you can match as many of these characters as there are in a row, or no characters if none of them exist in this position.
    • $ – The match must end at the end of the line (or entire string).

    In short, you’re only excluding those four special characters from the first character of your string, but you’re exluding all special characters as any character after the first.

    If you want to allow any character, except those four, in any position in the string, then you should use this as your pattern:

    /^[^0-9@&()]*$/
    

    With all of that said, I think you might be overcomplicating things a bit. It’s sort of a matter of opinion, but I try to only use regular expressions when there is no other way to do something, since they can be a bit hard to read (this question is a good example of that).

    What I would suggest is that you just use str_replace to remove the four characters you’re disallowing, and check the resultant string against your original input:

    if($input === str_replace(array('@', '&', '(', ')'), '', $input) {
      // process valid input
    } else {
      // handle invalid input
    }
    

    The str_replace call will take your original string and replace any value in the search array, array('@', '&', '(', ')'), and remove it (technically, “replace” it with nothing). If the two strings match after that, then none of the invalid characters were present, and your input is valid.

    Since you’re using parentheses as items within the array, it might be more readable to separate the elements onto their own lines:

    $chars_to_remove = array(
                         '@',
                         '&',
                         '(',
                         ')'
                       );
    if ($input === str_replace($chars_to_replace, '', $input)) {
      // process valid input
    } else {
      // handle invalid input
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a regex containing character set which can contain a period
<a href=/search?hl=en&amp;pwst=1&amp;sa=X&amp;ei=RCPqTqkHycryA_bK_f0J&amp;ved=0CCUQvwUoAQ&amp;q=psychology&amp;spell=1 class=spell><b><i>psychology</i></b></a> Hi, I'm looking to create a regex which matches this anchor
I am looking for a regex to create a string of characters with the
I'm trying to create a Regex to check for 6-12 characters, one being a
I am looking for a regex to replace all terms in parentheses unless the
I am trying to create documentation automatically from the code for all the URLs
I'm trying to create a regex to match anything else but ACTIONLOGDIR=/vz/actionlog. So far,
With a PHP function I'm trying to create a RegEx string for preg_replace that
I'm looking to create a regular expression in python that matches all DNA sequences
I'm trying to create a regex to recognize English numerals , such as one

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.