如何防止在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/