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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:37:26+00:00 2026-05-23T17:37:26+00:00

I wanted to allow only characters in a textbox and space in between two

  • 0

I wanted to allow only characters in a textbox and space in between two characters.I am trying to avoid any unwanted characters and blank string in following Javascript code.

var filter = "^[a-zA-Z''-'\s]{1,40}$";
        var label = $('#<%= txtName.ClientID %>').val();

        if ((label.length > 0) && (label!= '')) {
            if (label.match(/^[a-zA-Z \s]{1,40}$/)) {
                if (label.match(/^\s$/)) {
                    alert("Please Enter a Valid name");
                    return false;
                }
                else {

                    $("#myModal").dialog('open');
                }
            }
            else {
                alert("Please Enter a Valid name");
            }
        }
        else {
            alert("Please Enter a Valid name");
        }

This is working fine for everything except when user enters more than 1 space in the textbox. I was thinking that label.match(/^\s$/)) will take care of blank string or blank spaces.

Thanks

  • 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-23T17:37:26+00:00Added an answer on May 23, 2026 at 5:37 pm

    It looks like this is a job for 0 or more (the RegEx *)! (Pardon the exclamation, I’m feeling epic this morning)

    /^\s$/ means “contains only one space”

    I believe you are looking for

    /^\s*$/ means “contains only zero or more spaces”

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

Sidebar

Related Questions

I wanted to allow only specific email domain. Actually I did it. What i
I wanted to allow for a method to get called, if a finger was
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
I have developed a blog application of sorts that I am trying to allow
I'm trying to add some features into my editor that allow to the user
For a Django application that I'm working on, I wanted to allow group membership
OpenID authentication is inherently browser based. If I wanted to allow an OpenID user
I wanted a text field to take only numbers ans some control keys and
To allow for flexible layouts, I wanted to create a subclass UIView that overrides
I have a Win Form with two columns and I wanted to have the

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.