To verify that a string consists of only printable ASCII characters, use a simple regular expression, for example
/^[ -~]+$/
It matches
^ - start of string binding[ -~]+ - one or more (due to + quantifier characters) that are in the range from place to tilde in the ASCII table:

- $ - end of line binding
For Unicode characters for printing, use the \PC Unicode category (matching any char, but a char control)) from XRegExp , as already mentioned:
^\PC+$
See regex demos:
<script src="http://cdnjs.cloudflare.com/ajax/libs/xregexp/3.1.1/xregexp-all.min.js"></script>
Wiktor stribiżew
source share