I'm looking to detect internationalized domain names and local portions in email addresses, and would like to know if there is a quick and easy way to do this with regex or otherwise in Javascript.
A simple browser-based utility that validates ASCII data. Just paste your ASCII text in the input area and you will instantly get the ASCII status in the output area. If the input contains only ASCII characters, you'll get a green badge, otherwise a red badge.
To identify the Non Unicode characters we can use either Google Chrome or Mozilla firefox browser by just dragging and dropping the file to the browser. Chrome will show us only the row and column number of the .
This should do it...
var hasMoreThanAscii = /^[\u0000-\u007f]*$/.test(str);
...also...
var hasMoreThanAscii = str .split("") .some(function(char) { return char.charCodeAt(0) > 127 });
ES6 goodness...
let hasMoreThanAscii = [...str].some(char => char.charCodeAt(0) > 127);
Try with this regex. It tests for all ascii characters that have some meaning in a string, from space 32
to tilde 126
:
var ascii = /^[ -~]+$/; if ( !ascii.test( str ) ) { // string has non-ascii characters }
Edit: with tabs and newlines:
/^[ -~\t\n\r]+$/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With