Skip to content

Instantly share code, notes, and snippets.

@jericrealubit
Created March 22, 2018 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jericrealubit/f1c1c93f5d2b4304f0f24c10041bf92a to your computer and use it in GitHub Desktop.
Save jericrealubit/f1c1c93f5d2b4304f0f24c10041bf92a to your computer and use it in GitHub Desktop.
Validate an input string if it is inside ASCII 32 - 126 range
/**
* Validate an input string if it is inside ASCII 32 - 126 range
* @param string
* @return true if all characters in the string are in range, else false
*/
var chkASCII32_126 = function(string) {
return !string.match(/[^\x20-\x7e]/g);
}
$(".chorusASCIIValidation").keyup(function() {
var $th = $(this);
if (! chkASCII32_126($th.val())) {
if (! $th.hasClass("error")) $th.addClass("error").parent().after("<label id='msg-error' class='error valid'>Please Enter a valid character. eg: A-Z a-z 0-9 . _ -</label>");
} else {
if ($(this).hasClass('error')) {
$(this).removeClass("error").parent().siblings('.error').remove();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment