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!

validating an address field

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
What is the best way to validate an address field? I want to make sure there are numbers as well as the street name in the address field.


Thanks In the begining
Let us first assume that there was nothing to begin with.
 
I suggest you read up on regular expressions in Perl. You can use the match operator (m/) to match a specific pattern. The pattern is a regular expression you create. Search the web & you'll find tons of resources, but be patient. It takes a little study to get the hang of it.

Just to give you an example, here's some code I wrote to verify if an email addres has the proper format, and has a specific domain. Sorry I don't have any code handy for your specific problem. If you find yourself in a jam, drop me an e-mail and I'll write you some code. gjn4b9@mizzou.edu

sub verify_mu_email_address
{
#Split the address in order to...
my ($front, $back) = split(/@/, $email);

#...get the length of the first part.
my $allChars = length($front);

#Try to match pattern.
if ($email =~ m/[\w]{$allChars}\@mizzou\.edu$/i)
{
return "TRUE"; #It matched.
}
else
{
return "FALSE"; #Didn't match.
}
}

Good luck,

Greg
_______________________________________
Constructed from 100% recycled electrons
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top