2014-02-18 2 views
0

사용자가 공백 만 추가하는 것을 방지하기 위해 ckeditor에서 유효성 검사를 구현하는 방법은 무엇입니까? 오늘의 답변은 대단히 감사하겠습니다. 다음공백에 대한 ckeditor 유효성 확인

내가 지금까지 검증을 위해 뭘하려 :

//Save note from ckeditor 
    $("input.save_note").click(function() 
    { 
     var note_id1 = $(this).attr("rel"); 
     var thiss1 = this; 
     var profile_user_id = $(this).attr("rel1"); 
     var txt=CKEDITOR.instances.editor1.getData(); 
     var no_space_txt = txt.replace(" ",""); 
//  var txt = txt1.replace(/ +(?=)/g,''); 
     var editor_val1 = CKEDITOR.instances.editor1.document.getBody().getChild(0).getText() ; 
     var editor_val = editor_val1.replace(/ +(?=)/g,''); 
//  if(editor_val == "") 
//  { 
//   alert('sak'); 
//   return; 
//  } 
     if(editor_val !=="" && editor_val !=="") 
     { 
     $(this).attr("disabled","disabled"); 
     var loading_img = addLoadingImage($(this),"before"); 
     jQuery.ajax({ 
      url: "/" + PROJECT_NAME + "profile/save-note-in-editor", 
      type: "POST", 
      dataType: "json", 
      data: { "profile_user_id" : profile_user_id , "note" : txt }, 
      timeout: 50000, 
      success: function(jsonData) { 
       if(jsonData){ 
        $("p#clickable_note_"+note_id1).hide(); 
        $(thiss1).hide(); 
        $(thiss1).siblings("input.edit_note").fadeIn(); 
        $("span#"+loading_img).remove(); 
         $(".alert-box").remove(); 
         $(".alert-box1").remove(); 
         $(".alert-box2").remove(); 
         showDefaultMsg("Note saved successfully.", 1); 
         $(thiss1).removeAttr('disabled'); 
//      $(".cke_inner cke_reset").hide(); 
         CKEDITOR.instances.editor1.destroy(); 
         $(".editor1").hide(); 
         $("p#clickable_note_"+note_id1).html(jsonData);//to display the saved note in clickable p tag . 
         $("p#clickable_note_"+note_id1).fadeIn('slow');// To display the note paragraph again after editing and saving note. 
        } 
        else{ 
         $(thiss1).removeAttr('disabled'); 
         $(thiss1).before('<span class="spanmsg" id="note-msg" style="color:red;">Server Error</span>'); 
        } 
       }, 
      error: function(xhr, ajaxOptions, thrownError) { 
       alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 
      } 
     }); 
     } 
     else 
     { 
      alert("You cannot make an empty note. Please insert some text."); 

     } 

    }); 

나는 텍스트가 입력되지 않은 경우 확인 경고 구현해야하지만 난 사용자가 공백 만 입력하면 확인하시기 바랍니다. 정확한 방법을 제안하십시오. 당신은 분명히 jQuery를 사용하고 있기 때문에

+0

여기까지 행운이 있습니까? – zeantsoi

+0

@zeantsoi 아니요. 나는 손질과 교체를 사용했지만 모두 도움이되지 않습니다. – Simer

답변

0

, 당신은 당신의 조건에 대한 추가 검사로 jQuery.trim()을 추가 할 수 있습니다

jQuery.trim(editor_val).length != 0 

이 제출 된 양식에서 모든 공백을 잘라 내고 남아있는 문자가 있는지 여부를 확인합니다. 입력이 공백으로만 이루어진 경우, 명령문은 false으로 평가됩니다. 다음 줄에 통합하십시오 :

if (editor_val != "" && editor_val != "" && jQuery.trim(editor_val).length != 0) 
+0

&& jQuery.trim (editor_val) .length! = 0 - 효과가있었습니다. thanks @zeantsoi – Simer

+0

정규 표현식을 사용하여 특정 문자열을 검색하는 것이 좋습니다. – zeantsoi

+0

나는 http://stackoverflow.com/questions/9741620/ckeditor-unwanted-nbsp-characters를 언급했다. 그리고 그것은 작동했습니다. 이제 출력 @zeantsoi에서  을 얻지 못하고 있습니다. – Simer