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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:57:16+00:00 2026-06-11T04:57:16+00:00

I basically have the following validation on my page – its a word rule

  • 0

I basically have the following validation on my page – its a word rule in that a description in a text box cannot be greater than 3 words excluding the word ‘and’. I have implemented the following server side validation in C# which is working fine

if (Desc.Trim().ToString() != "")
{
    MatchCollection collection = Regex.Matches(Desc.Replace("and", ""), @"[\S]+");

    if (collection.Count > 3)
    {
        ErrorMsg.Append("Description should contain at most 3 words(excluding 'and').");
        ErrorMsg.Append("\\n");
    }
}

However I am having difficulty getting the same working in Javascript. I have tried the following but it isnt working so far so hoping for someone that has a better knowledge of Javascript can see the error. Note the if is part of a bigger validate function that fires on the page – the alerts were just there to see if it got into this if (which it doesnt) – when this is block is removed the rest of the JS on the page is working fine.

if (Desc.val().trim() != "")
{
    alert('1');
    !regexWordRule.test(Desc.val());
    alert('2');

    if (Desc.val().match(regexWordRule).length > 3)
    {
        errorText += "Description should contain at most 3 words(excluding 'and').";
    }

    valid = false;
}

and the below is my regexWordRule defined at the very top of the js file.

var regexWordRule = /[\S]+/;
  • 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-11T04:57:17+00:00Added an answer on June 11, 2026 at 4:57 am

    You could find a better solution, but this approach came to my mind, so I am posting it:

    var input = "and lorem and ipsum";
    
    // remove ands
    var deandizedinput = input.replace(/\band\b/g, ' ');
    
    // replace all white spaces with a single space
    var normalizedinput = deandizedinput.replace(/\s+/g, ' ');
    
    // split the input and count words
    var wordcount = normalizedinput.trim().split(' ').length;
    

    Fiddle here.

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

Sidebar

Related Questions

Basically I have a new client that is after the following functionality from her
I have the following code for the jQuery validation plugin.... basically on submit, I
I basically have multiple divs that contain information for different words (word, definition, ect.)
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I am wondering if the following is possible in MVC 3 I basically have
I have the following views in my application. Basically I want to call show_house()
I have created following thing in android using android compatibility support package Basically i
Basically, I have the following so far: class Foo { public override bool Equals(object
Is there any name for the following DB table design: Basically we have generic

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.