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

  • Home
  • SEARCH
  • 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 8580113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:45:29+00:00 2026-06-11T20:45:29+00:00

I need to validate a string to allow only a specific set of characters

  • 0

I need to validate a string to allow only a specific set of characters using regex. Unfortunately, I am stuck using regex only for the validation of these strings.

Anyways I need to limit a string to allow only the following characters:
a-z and A-Z and 0-9 and space and .,;:!=+-_

For this I have created the following expression:

[a-zA-Z0-9.,;:!=+-_\s]*

I can’t figure out why this expression is not working. The following test strings when I am using this are giving me the following results:

<test> Valid 
$<test> Invalid 
test Valid 
<test>asdf</test> Invalid

It appears the order of these special characters is being taken into account when really all I need to to limit the validation to a specific list of valid characters regardless of the order in the string.

Can anyone shed some light on why this may be allowing special characters such as ‘<>’ but only in certain orders?

  • 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-11T20:45:30+00:00Added an answer on June 11, 2026 at 8:45 pm

    use anchors and shild symbol -

    ^[a-zA-Z0-9.,;:!=+\-_\s]*$

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

Sidebar

Related Questions

Really got stuck on this simple regex. Need it to validate a string, that
I need to validate following string using Regular Expressions. These are the constraints which
I need a regex or a function in PHP that will validate a string
I need a regular expression to validate string with one or more of these
I need to add some validation that will only allow one capital letter in
I need to validate input to my application. The input is a formatted string
I need to validate file name with following pattern.... File name(string) should not be
Possible Duplicate: Php function to determine if a string consist of only alphanumerical characters?
I'm using this code to validate string. $countrecipient ='0123456789'; preg_match('/^[0]{1}[1]{1}[0-9]{1}[0-9]{7}?$/', $countrecipient) How if I
i need to validate this type of string 0415256987, 0452 654 987, 0411 236589,

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.