Skip to content

Instantly share code, notes, and snippets.

@suebphatt
suebphatt / username_input.js
Last active May 30, 2018
USERNAME INPUT FIELD JS - english only / no space / allows special chat only _
View username_input.js
// -- 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
ONLY NUMBER JS -- Allow only number to be typed on input field, also works on mobile
View only-number.js
// -- 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
ENGLISH ONLY JS -- OnKeyup english only input type=text, also works on mobile
View english-only.js
// -- english only
$(".english-only").on('keyup change', function(event){
var sanitized = $(this).val().toString().replace(/[^\u0000-\u007F]+/, '');
$(this).val(sanitized);
});