Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Count and limit the number of words in a textbox

Posted on 2006-05-22
4
Medium Priority
?
974 Views
Last Modified: 2012-05-05
I need to limted the number of words a user can enter into a textbox on an asp.net webform.  I suppose that the words need to be counted as the user is entering them and then stopped when they reach the maximum word count.  Does anybody have any examples of how to do this?

Any help would be appreciated.

0
Comment
Question by:Mike_Stevens
3 Comments
 
LVL 3

Accepted Solution

by:
rstrader earned 800 total points
ID: 16736582
to limit the max number of characters in a textbox you can use a regularexpressionvalidator with validationexpression="^[S\s\]{1,200}$"

this would limit the texbox to 200 characters. (I use this)

you might try something like
"^[\b(\w+?)\b]{1,10}$"  would allow 10 words

0
 
LVL 7

Assisted Solution

by:sukumar_diya
sukumar_diya earned 800 total points
ID: 16736587
Dude,
Get the no of words by spliting the text by space. and check the length of the words with the max words allowed. Please check the code below..

<script language="javascript">
function CheckLength(value,MaxCount)
{
value = value.replace("\s\s"," ");
var words = value.split(" ");

if(words.length>MaxCount)
{
   return false;
}
else
{
   return true;
}
}

function txtValue_KeyPress()
{
      var value = document.getElementById("txtvalue").value;
      return CheckLength(value,15);
}

document.getElementById("txtvalue").onkeypress = txtValue_KeyPress;

</script>

Hope this helps you,
Suku
0
 
LVL 4

Assisted Solution

by:RJeyaPrakash
RJeyaPrakash earned 400 total points
ID: 16739798
hai

why dont u use the maxlength property of text boxes which will do exactly the same as yr requirement


regs
jp
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question