Created
March 22, 2018 20:29
-
-
Save jericrealubit/f1c1c93f5d2b4304f0f24c10041bf92a to your computer and use it in GitHub Desktop.
Validate an input string if it is inside ASCII 32 - 126 range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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