Hi again
Still dont get these regular expressions, i,ve seen the examples, but they dont show you the correct way to search for a particular pattern and make sure that the string is conforming to the rest of the rules.
I guess maybe i,m missing something, and untill I can understand what a script actually does, then there,s now way i,ll be using it, and this is because of two reasons.
Bad idea security wise.
It takes all the fun out of it.
So this is what I have ended up with so far.....
function validate_email() {
global $email, $error;
$valerror = "<br>Your <strong>Email address</strong> doesnt appear to be in the <strong>correct format</strong>!";
$emailarray = explode("@", $email);
if (!$emailarray[1]) {
$error = $valerror;
registration_form();
return;
}
elseif (!is_null($emailarray[2])) {
$error = $valerror;
registration_form();
return;
}
else {
$patternBefore = "/^([a-z0-9]{1,})$/";
$patternAfter = "/^([a-z0-9?\-]{3,})$/";
if (preg_match($patternBefore, $emailarray[0])) {
$beforeOk = "1";}
if (preg_match($patternAfter, $emailarray[1])) {
$afterOk = "1";}
if ($beforeOk && $afterOk) {
echo "<br><br>Email good";
} else {
$error = $valerror;
registration_form();
}
}
}
I,ve split the address into 2 at the @, like gammaster's suggestion, and then check to make sure that there,s atleast 1 @ but no more.
If everything is well, then it continue,s to check the split email, against the 2 patterns.
Each error throws the user back to the registration form with an error message.
Sorted, but if you look at the afterpattern, I still need to add something to it. Basically I want the user to be able to input optional characters at the end, these will be a . and if thats there then this is also required a-z{2,3}.
As you can see I know the single options, but I cant combine then.
The frontpattern also needs work, but if someone can show how to do backpattern, then I may be able to it myself.
And then there,s also the problem of not allowing a pattern like so .. on both parts.
L8rs guys
Thx for the help so far