01 Nov 2008, 00:00

Check String for Non-ASCII Characters in Perl

Check String for Non-ASCII Characters in Perl

if ( $string =~ /[[:^ascii:]]/ ) {
    print "String contains characters that are NOT pure ASCII";
}
else {
    print "Everything is good, string/pure is valid ASCII.";
}

E.G.: If it contains bytes > 127, it’s not valid ASCII.