Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering non-ascii/non-latin chars in perl-cgi

Status
Not open for further replies.

GLCHY

Programmer
Mar 16, 2002
3
US
Hi,

i have a simple HTML form which i post from IE 6.02 to a perl-cgi script (Solaris 2.6 and PERL 5). I just want to detect non-ASCII chars (or those chars NOT used on the standard American keyboard) and flag an error message. Eg. if user send english text, then proceed but if some japanese/chinese chars are copy-pasted (from a japanese/chinese website) onto my form which is then posted to my perl script, then display error message.

I have not set up the charset in the HTML header of the form. Trying regular expression in the perl script, ie accepting only alphanumerics and symbols does not 'trap' the japanese/chinese chars (which are not displayed as such on UNIX but as weird symbols!). Ive even tried to use the IsASCII and InBasicLatin function in an if-else statement but i could not trap the non-ASCII chars.

my $a = $in{mesg};
if ( ($a =~ /\p{InBasicLatin}+/) ||($a =~ /\p{InLatin-1Supplement}+/) || ($a =~ /\p{InLatinExtended-A}+/) || ($a =~ /\p{InLatinExtended-B}+/) || ($a =~ /\p{InLatinExtendedAdditional}+/) || ($a =~ /\p{IsASCII}+/) {
print STDERR "Cool Latin/ASCII!\n"; }
else {print STDERR "Chars NOT allowed!\n";}

Is there of any way or any modules that will solve my problem?

Thanks for the help.

GC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top