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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limiting form fields to alpha numeric input only

Status
Not open for further replies.

quan

Programmer
Oct 3, 2001
58
US
Hello,

I need some script that will test to make sure that a person has only entered alpha-numeric data into a form and not any special characters such as ",%!'" etc

Basicly a person will fill out a form, which then will get parsed. I would like to test all the fields of the form hash for alpha numeric characters input. If data has anything but alphanumeric, I will call a error subroutine which prompts the user to re-enter the data.

Thanks for the help <i>Its okay to dream.....</i>
 
$input = &quot;some text and number 123 and %)&quot;
$input =~ tr/0-9/ /cs;
$input =~ s/\s//g;
# now $iput is eq to '123'
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I think what he wants is something like this

foreach (keys %formdata)
{
Error() if $formdata{$_} =~ /[^A-Za-z0-9]/;
}

sub Error
{
# Error code here
}

This will check each hash pair in a hash of form variables and will execute sub Error if any of them contain anything other than an alphanumeric.

This is just a thought but, you can also use javascript to accomplish the same thing from the client side. However, you would always want to check on the server side in case someone happens to turn javascript off.
 
Cool, yes, that is exactly what I need, thanks a million,and yes, I am posted in the java forum too, for server side.

Thanks <i>Its okay to dream.....</i>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top