Forum Moderators: coopster
Well I am working on Form Validation with PHP. I have been looking at many tutorials and all of them have given the code to validate but havent explained how it works.
Basically I have this script:
function valid_email($address) {
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address)) {
return true;
} else {
return false;
}
}
It validates an email address. How does it work? How can I manipulate it to validate other inputs, such as address, phone numbers or any kind of input?
Thanks for your help :)
Wes
^
means to start at the beginning of the string.
[a-zA-Z0-9_\.\-]
looking for a-z or A-Z or 0-9 or - or .
+
@
looking for the the "@"
[a-zA-Z0-9\-]
looking for a-z or A-Z or 0-9 or -
+
\.
looking for a period
[a-zA-Z0-9\-\.]
looking for a-z or A-Z or 0-9 or - or .
+
$
First get an idea of what it's all about with the following tutorial:
[phpfreaks.com...]
Then look at this more advanced one:
[phpfreaks.com...]
After you read through those two, tested the examples etc. you shouldn't have too many problems validating your form entries.
best regards
adrian