How to block emoticons from input text field in codeignitier

Multi tool use
How to block emoticons from input text field in codeignitier
I want to make input text field in such a way that it will block emoticons entry in text input field. I have made validation on controller for particular route by passing.Is it is a right way to block emoticons.
Controller code.
$this->form_validation->set_rules('registration', 'Registration', 'required|alpha_numeric');
$this->form_validation->set_rules('odometer', 'Odometer', 'required|alpha_numeric');
view code:
<input type="text" name="odometer" placeholder="Odometer" class="form-control profileControl odometer required number" id="odometer-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->intCarOdometer ?>"/>
<input type="text" placeholder="Registration" name="registration" class="form-control profileControl registration required" id="registration-<?php echo $vehicle_count; ?>" value="<?php echo $vehicle->vchCarRegistration ?>" pattern="[a-zA-Z0-9]+"/>
alphanumeric validation on text input is right way to block emoticons?
– PriyaNegi
Jul 2 at 4:48
no, it maybe exists some character that required.
– AbdulAhmad Matin
Jul 2 at 4:57
can i add this script in view ?
– PriyaNegi
Jul 2 at 4:59
yes now it is
onclick
you can change it to onkeyup
the input
– AbdulAhmad Matin
Jul 2 at 5:00
onclick
onkeyup
input
1 Answer
1
You can remove emoticons before sending to the server with jquery.
test this code.
var ranges = [
'ud83c[udf00-udfff]', // U+1F300 to U+1F3FF
'ud83d[udc00-ude4f]', // U+1F400 to U+1F64F
'ud83d[ude80-udeff]' // U+1F680 to U+1F6FF
];
setTimeout(removeInvalidChars, 100);
function removeInvalidChars() {
var str = $('.valid-text').val();
str = str.replace(new RegExp(ranges.join('|'), 'g'), '');
$(".valid-text").val(str);
setTimeout(removeInvalidChars, 100);
}
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<input id="myinput" class="valid-text" type="email" name="myinput" value=" 😀 value 1 2 3 ? / "></input>
10 ms for timeout is way too fast (performance issues). 100 would probably be a better value
– Binar Web
Jul 2 at 10:05
100 is very long maybe between this 100ms user save the data and send it to the server.
– AbdulAhmad Matin
Jul 2 at 10:15
I don't see it possible to type the some text in the input and then send the form in 100ms from keyboard and mouse. Not to mention that the emoticons can be removed when the form gets submitted.
– Binar Web
Jul 2 at 10:35
Now it is 100ms. Thanks
– AbdulAhmad Matin
Jul 2 at 10:49
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
yes it works but also you can remove it before sending to server on click with jquery
– AbdulAhmad Matin
Jul 2 at 4:45