Testing something

http://stackoverflow.com/questions/7114185/javascript-validate-user-input-against-desired-character-set-encoding get back to that poor guy

by nwellcome

HTML

<html>
    <head>
    </head>
    <body>
        <textarea id="input" rows="10" cols="50">
            ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~   ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬  ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ Œ œ Š š Ÿ Ž ž ƒ ˆ ˜ – — ‘ ’ ‚ “ ” „ † ‡ • … ‰ ‹ › € ™
        </textarea>
        <div id="output"></div>
    </body>
</html>

CSS

.bad {
    background-color: red;   
}

JavaScript

function isNotAllowed(char) {
    var a = char.charCodeAt(0);
    b = a.toString(16);
    b = (b.length < 3 ? "0" + b : b);
    b = (b.length < 4 ? "0" + b : b);
    console.log(b);
    return (a < 
    return /\x00-\x1f|\x7f-\x9f/.test(char); // 00 to 1f, or 7f to 9f
}

$(document).ready(function() {
    var str = $("#input").val();
    var outStr = "";
    for (var i = 0; i < str.length; i++) {
        if (isNotAllowed(str[i])) {
            outStr += '<span class="bad">' + str[i] + '</span>';
        } else {
            outStr += str[i];
        }
    }
    $("#output").html(outStr);
});