01 Nov 2008

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.