Click here to Skip to main content
15,891,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I am using an Ajax HtmlEditorExtender for Description field in my application.

My Sample Code:

ASP.NET
<asp:TextBox ID="txtDescription" TextMode="MultiLine" Height="100" CssClass="text" runat="server" />
<ajax:HtmlEditorExtender ID="HtmlEditorExtender2" TargetControlID="txtDescription" runat="server">
       <Toolbar>
            <ajax:Bold />
            <ajax:Italic />
            <ajax:Underline />
            <ajax:HorizontalSeparator />

             <ajax:JustifyLeft />
             <ajax:JustifyCenter />
             <ajax:JustifyRight />
             <ajax:JustifyFull />
             <ajax:HorizontalSeparator />

             <ajax:InsertUnorderedList />
             <ajax:ForeColorSelector />

        </Toolbar>
 </ajax:HtmlEditorExtender>


This description textbox is accepting empty spaces when i tried with space bar and enter key. The Description field is mandatory and so it should not accept empty spaces.

I am unable to validate this control(txtDescription) using FilteredTextBoxExtender/RequiredFieldValidator/Javascript validation.

Help me out pls!!
Posted
Updated 18-Apr-12 0:57am
v3

1 solution

Did you try anything?

To start with:
JavaScript
function CheckBlankSpace(txtBoxId) 
{
     var tb = document.getElementById(txtBoxId);

     // Trim white space if any before taking value length
     var tbLen = tb.value.trim().length;
     if (tbLen == 0)
     {
        // Raise error or do whatever you like
     }
}


Modify it as per your need.
 
Share this answer
 
Comments
Jithin cool 20-Apr-12 0:20am    
I tried the above code by pressing space bar in the description field and got the value as follows,
"tb" value - "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>"

"tbLen" value = 81

Thoughts pls!!!
Sandeep Mewara 20-Apr-12 1:25am    
Try something like this in start: var actualtbvalue = tb.value.replace(/(& nbsp ;)*/g,"");
// & nbsp ; - without space
Jithin cool 20-Apr-12 1:48am    
I tried this ,
var tbLen = $("#txtDescription").val().replace(/(& nbsp ;)*/g, "");

"tbLen " value - "        <br>"

I got the same value by pressing space bar in description field. The field is accepting empty spaces.
Sandeep Mewara 20-Apr-12 4:00am    
Using jQuery is easier:
Use the replace function in js:
Try:
var tbValue = $(this).text().replace(/ /g,''); //That will remove all the spaces

If you want to remove the leading and trailing whitespace only:
var tbValue = $.trim($(this).text());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900