Using Bootstrap form builder, I want to know how I can restrict user from entering #
and .
into the property of a label, where contenteditable
is true.
I want this to be implemented for any random label that is going to be edited. How to do that?
I am aware of the ascii values for that but for all the labels present in that page when content editable is true i want user not to input #
and .
into it.
My label sample is this:
<label>
<strong contenteditable="true">Telephone</strong>
</label>
I tried using this but does not prevent it from typing # & .
$('body').on('paste input', '[contenteditable]', function(data) {
var text = $(this).text();
if (text == '#' || text == '.'){
console.log('hi');
data.preventDefault();
}
});
working now
$('body').on('paste input', '[contenteditable]', function(data) {
var text = $(this).text();
var regax1 = /#/;
var regax2 = /./;
if (text.match(regax1)) {
var newText = text.replace('#', '');
$('strong').text(newText);
}
});
});