2016-06-28 4 views
0

내 텍스트 입력란 및 텍스트 영역에있는 모든 이모티콘을 허용하지 않습니다.Ionic : 모든 이모티콘 허용하지 않음

현재 모든 입력에서 전체 텍스트가 검사되고 이모티콘이 있으면 허용되지 않는 알림이 표시됩니다.

전체 문자 대신에 마지막 문자 만 검사된다는 것은 어떻게 달성 할 수 있습니까?이 문자가 이모티콘이면 표시되지 않습니다 (차단됨) ? 또한, 현재 정규 표현식에서는 일부 이모티콘 (눈이나 신발과 같은 특수한 것) 만 허용하지는 않습니다 (예 : 일반적인 스마일리 또는 혀 스마일). 어떻게 모두 차단할 수 있습니까?

내 코드를 지금까지 (HTML) :

app.directive('noEmoticons', function ($timeout) { 
    return function (scope, element, attrs) { 
    var emoticonDetected; 
    element.bind("keydown", function (event) { 
     var text = $('#message-textarea').val(); 
     if(text.match(/([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g, '')){ 
     emoticonDetected = true; 
     } else { 
     emoticonDetected = false; 
     } 
     scope.$emit('clicked-from-directive-emoticon', {emoticonDetected}); 
    }); 
    }; 
}); 

답변

1

확인

<textarea ng-model="postcard.textBack" id="message-textarea" no-emoticons></textarea> 

이온, 다음 지시문의 모든 그림 이모티콘 블록과 바로의를 삭제합니다.

HTML

각도
<textarea ng-model="postcard.textBack" id="message-textarea" no-emoticons></textarea> 

/이온

app.directive('noEmoticons', function ($timeout) { 
    return function (scope, element, attrs) { 
    var el = $('#message-textarea'); 
    var emoticonDetected; 
    var emojiRegex = /(?:0\u20E3|1\u20E3|2\u20E3|3\u20E3|4\u20E3|5\u20E3|6\u20E3|7\u20E3|8\u20E3|9\u20E3|#\u20E3|\*\u20E3|\uD83C(?:\uDDE6\uD83C(?:\uDDE8|\uDDE9|\uDDEA|\uDDEB|\uDDEC|\uDDEE|\uDDF1|\uDDF2|\uDDF4|\uDDF6|\uDDF7|\uDDF8|\uDDF9|\uDDFA|\uDDFC|\uDDFD|\uDDFF)|\uDDE7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122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267B\u267F\u2692-\u2694\u2696\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD79\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED0\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3]|\uD83E[\uDD10-\uDD18\uDD80-\uDD84\uDDC0]/g; 
    element.bind("keyup", function (event) { 
     var text = el.val(); 
     if(text.match(emojiRegex, '')){ 
     emoticonDetected = true; 
     el.val(el.val().slice(0, -1)); 
     event.preventDefault(); 
     } else { 
     emoticonDetected = false; 
     } 
     scope.$emit('clicked-from-directive-emoticon', {emoticonDetected}); 
    }); 
    }; 
}); 
관련 문제