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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:22+00:00 2026-06-18T03:16:22+00:00

I wanted to know how I can specify character count for my regex. I

  • 0

I wanted to know how I can specify character count for my regex.
I have the correct regex, I only need to make sure this will work validating zero to fourty characters.

here is the regex

$fnameRegex = "/^[a-zA-Z0-9{0,40}-_]+$/";

i might have put the {0,40} in the wrong place.

  • 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-18T03:16:23+00:00Added an answer on June 18, 2026 at 3:16 am

    Try

    $fnameRegex = "/^[a-zA-Z0-9\-_]{0,40}$/";
    

    Everything in a character class [] will only match one character. You put the quantity limiter outside it (you previously had + which is 1 or more – replace it with {0, 40} which is between 0 and 40).

    Also I escaped your - character in your character class, or else it will be interpreted as a range.

    I also recommend to you the great regexr website which is good for interactively playing around with regex.

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

Sidebar

Related Questions

Thanks for looking at this question. I wanted to know how can I use
To make a poll form using an applet, i wanted to know how can
I wanted to know if we can have a unique identifier for all objects
I just wanted to know if I can point to class using this implementation:
I wanted to know can we have images as a values in properties file
I wanted to know can my cfml page or cfc components with with only
I wanted to know why do we need to specify the Annotation @XmlAccessorType when
I wanted to know how can I have an application bar in Panorama screen
I wanted to know how can we get the index of the array if
Hello I am new to MATLAB , I wanted to know how can I

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.