如何防止在cleditor中输入和粘贴单引号和双引号? [英] how to prevent entering and pasting single and double quotes inside cleditor?
本文介绍了如何防止在cleditor中输入和粘贴单引号和双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止在cleditor中输入和粘贴单引号和双引号? 如何防止在cleditor中输入和粘贴单引号和双引号?
how to prevent entering and pasting single and double quotes inside cleditor? how to prevent entering and pasting single and double quotes inside 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>
推荐答案
请尝试使用此方法,此解决方案是防止在输入和粘贴时使用双引号和单引号.
Please try this one, This solution is to prevent double quotes and single quotes while entering and pasting.
$(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/
这篇关于如何防止在cleditor中输入和粘贴单引号和双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文