I'm trying to make sure that a string does not have any weird ASCII characters.
I'm trying to use character classes and negation.
var tester =/[^\x00-\x001F\x007\x080-\xA1]+/i;
So: no ASCII characters between 00-1F, 07; or 80-A1 should be present. Everything else should be fine.
I am coming back to regular expressions after a long time away... The regular expression is NOT working. I want a string like "hello" to pass and a string like "†ack!" to fail. Or, is my JavaScript/jQuery code wrong?
The code:
var tester2 = /^[^\x00-\x1f\x80-\xa1]+$/;
$('#testButton').click(function(){
var text1 = $('#ackInput').val();
console.log("text: " + text1);
var allowed = tester2.test(text1);
var feedback = "allowed?" + allowed;
console.log(feedback);
$('#errorTestInputAllowedChars').text(feedback);
});
An entry on jsFiddle is at http://jsfiddle.net/jillrenee42/WE79e/2/.