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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:00:22+00:00 2026-06-08T18:00:22+00:00

I am complete novice at regex and Javascript. I have the following problem: need

  • 0

I am complete novice at regex and Javascript. I have the following problem: need to check into a textfield the existence of one (1) or many (n) consecutive * (asterisk) character/characters eg. * or ** or *** or infinite (n) *. Strings allowed eg. *tomato or tomato* or **tomato or tomato** or as many(n)*tomato many(n)*. So, far I had tried the following:

var str = 'a string'
var value = encodeURIComponent(str);
var reg = /([^\s]\*)|(\*[^\s])/;

if (reg.test(value) == true ) {
    alert ('Watch out your asterisks!!!')
}
  • 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-08T18:00:23+00:00Added an answer on June 8, 2026 at 6:00 pm

    By your question it’s hard to decipher what you’re after… But let me try:

    Only allow asterisks at beginning or at end

    If you only allow an arbitrary number (at least one) of asterisks either at the beginning or at the end (but not on both sides) like:

    • *****tomato
    • tomato******
    • but not **tomato*****

    Then use this regular expression:

    reg = /^(?:\*+[^*]+|[^*]+\*+)$/;
    

    Match front and back number of asterisks

    If you require that the number of asterisks at the biginning matches number of asterisks at the end like

    • *****tomato*****
    • *tomato*
    • but not **tomato*****

    then use this regular expression:

    reg = /^(\*+)[^*]+\1$/;
    

    Results?

    It’s unclear from your question what the results should be when each of these regular expressions match? Are strings that test positive to above regular expressions fine or wrong is on you and your requirements. As long as you have correct regular expressions you’re good to go and provide the functionality you require.

    I’ve also written my regular expressions to just exclude asterisks within the string. If you also need to reject spaces or anything else simply adjust the [^...] parts of above expressions.

    Note: both regular expressions are untested but should get you started to build the one you actually need and require in your code.

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

Sidebar

Related Questions

I'm a complete novice when it comes to regex. Could someone help me convert
I'm a complete SQL novice, and I'm trying to accomplish the following (pseudo-code) with
As a complete Javascript novice I'm challenged by some simple concentps. When I'm doing
complete novice at work (who is also ill and feeling particularly thick) I have
(I'm a complete novice programmer) I recently came across a problem with my custom
My apologies but I am a complete novice. Hopefully a quick one for you
I don't consider myself a complete SQL novice, but I have been staring at
I am a complete novice at php and postgres. I have been searching all
First off, I'm a complete novice as a web developer. I have a PHP
I'm a complete novice, looking for instructions on implementing javascript. I am attempting to

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.