Reputation: 4524
I have a ascx file in which i am using text box with tinyMCE editor. code is following..
<asp:TextBox ID="txbDiag" TextMode="MultiLine" runat="server" Width="100%" Height="100px"/>
<acr3s:tinymceextender runat="server" ID="TinyMceExtender4" TargetControlID="txbDiag" Theme="Full"/>
like this i have using 5 text box with tinyMCE extender
I am trying to validate my textbox with spacebar, If someone open my page and in text box click on spacebar and click on btn save it should not accept the value and give the error field should not be empty. the code which i use to validate is
if (txbDiag.Text.Trim().Length <= 0)
{
msgError.Text = "<b><font Color=red>*" + "fields are mandatory"+"</font>";
msgError.Focus();
return false;
}
and on btn click i use
txbDiag.Text.Trim();
but while clicking on btn save page is getting saved.
i used the js
<script type="text/javascript">
function validate(e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if (unicode == 32) {
return false;
}
else {
return true;
}
}
</script>
but this is also not working
I used regular expression and requir field validation that also not causing validation
HOW COULD I VALIDATE MY TEXT BOX FROM SPACEBAR HELP ME????
Upvotes: 1
Views: 2334
Reputation: 4524
if (Textbox1.Text.Replace(" ", "").Replace("<br />", "").Trim().Length <= 0)
{
//Statement here
}
Upvotes: 0
Reputation: 50832
Ok, first you need to know that tinymce is NOT inside a textbox. Tinymce will create a contenteditable iframe and write back the content to a specified html element (textareas, divs, ps, aso...) from time to time on special events. So grabbing the txbDiag.Text is not very reliable. I suggest you use the tinymce API functions to get the content in order to verify it.
1. to get the right editor use
var my_editor = tinymce.get('txbDiag');
2. get the content
var my_content = my_editor.getContent();
3. Verification of the content: I am not sure what you want to verify exactly! (eighter that a space has been selected, that the content is empty or something else - please describe this EXACTLY)
In case you want to verify if the input is empty you can use
if ($(my_editor.getBody()).text() == '') alert('The input may not be empty!');
Upvotes: 1
Reputation: 1674
Why don't you trim it on the user's side? I would do the JS like:
if (yourTextBoxInnerPart.trim() == "")
{
//textBox is empty or filled with spaces..
}
Upvotes: 0