[英]how to prevent entering and pasting single and double quotes inside cleditor?
如何防止在 cleditor 中輸入和粘貼單引號和雙引號? 如何防止在 cleditor 中輸入和粘貼單引號和雙引號?
<script type="text/javascript">
$(document).ready(function(){
$prevent_single_double_quote = function(e){
var element=e;
setTimeout(function () { element.val(element.val().replace(/['"]/g, "")); }, 1);
}
$('textarea').on('paste', function () {
$prevent_single_double_quote($(this));
});
$('textarea').on('keyup', function () {
$prevent_single_double_quote($(this));
});
$('input').on('paste', function () {
$prevent_single_double_quote($(this));
});
$('input').on('keyup', function () {
$prevent_single_double_quote($(this));
});
$('.scle').on('keyup', function () {
$prevent_single_double_quote($(this));
});
});
</script>
<div class="col-md-9">
<div class="block block-fill-white" id="mailcontent">
<div class="content np" id="mailcontent">
<textarea class="scle" name="mailcontent" id="mailcontent"></textarea>
</div>
</div>
</div>
$(document).ready(function() {
$prevent_single_double_quote = function(e) {
var element = e;
setTimeout(function() {
var regexFormat = /^[a-zA-Z0-9 ]*$/;
var text = element.val();
if(!regexFormat.test(text)){
//if contains single or double quotes.
text = text.substring(0, (text.length-1));
}
element.val(text);
}, 1);
};
$('textarea').on('change', function() {
$prevent_single_double_quote($(this));
});
$('textarea').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('input').on('change', function() {
$prevent_single_double_quote($(this));
});
$('input').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('.scle').on('keyup', function() {
$prevent_single_double_quote($(this));
});
});
希望這可能奏效!
請試試這個,這個解決方案是在輸入和粘貼時防止雙引號和單引號。
$(document).ready(function() {
$prevent_single_double_quote = function(e) {
var element = e;
setTimeout(function() {
var regexFormat = /^[a-zA-Z0-9\[\]\$\!\#\%\^\&\*\(\)\-\+\=\-\;\:\,\.\?\@\_\' ]*$/;
var text = element.val();
if(!regexFormat.test(text)){
//if contains single or double quotes.
text = text.substring(0, (text.length-1));
}
element.val(text);
}, 1);
};
$('textarea').on('change', function() {
$prevent_single_double_quote($(this));
});
$('textarea').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('input').on('change', function() {
$prevent_single_double_quote($(this));
});
$('input').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$('.scle').on('keyup', function() {
$prevent_single_double_quote($(this));
});
$( "input" ).bind( 'paste',function()
{
var txtbx = $(this);
setTimeout(function()
{
//get the value of the input text
var data= $( txtbx ).val() ;
//replace the special characters to ''
var dataFull = data.replace(/((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)/gi, '');
//set the new value of the input text without special characters
$(txtbx).val(dataFull);
});
});
});
請參閱此處的示例: https : //jsfiddle.net/Shalitha/nfovt6bz/26/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.