Skip to content

Instantly share code, notes, and snippets.

@suebphatt
suebphatt / username_input.js
Last active May 30, 2018 09:17
USERNAME INPUT FIELD JS - english only / no space / allows special chat only _
// -- username input
$("#username").on('keyup change', function(event){
var sanitized = $(this).val().toString().replace(/[^\u0000-\u007F]+/, '').replace(/ /g, '').replace(/[^\w\s]/gi, '');
$(this).val(sanitized);
});
@suebphatt
suebphatt / only-number.js
Last active May 30, 2018 08:27
ONLY NUMBER JS -- Allow only number to be typed on input field, also works on mobile
// -- number only 2
$(".only-number").on('keyup change', function(){
// Remove invalid characters
var sanitized = $(this).val().toString().replace(/[^0-9]/g, '');
// Update value
$(this).val(sanitized);
});
@suebphatt
suebphatt / english-only.js
Last active May 30, 2018 08:27
ENGLISH ONLY JS -- OnKeyup english only input type=text, also works on mobile
// -- english only
$(".english-only").on('keyup change', function(event){
var sanitized = $(this).val().toString().replace(/[^\u0000-\u007F]+/, '');
$(this).val(sanitized);
});