...

View Full Version : can someone please help me convert the Javascript to PHP



jasonpc1
05-30-2011, 11:15 PM
<script type="text/javascript">
function checkEmailValid(email) {
s = email.indexOf(' ') + 1;
e = email.indexOf('@') + 1;
f = email.indexOf('.') + 1;
if ( email != '' && s == 0 && e && f > e + 1 && f < email.length) {
return true;
} else {
return false;
}
}
</script>


this would allow i.e.

1@1.1
a@a.a

or any number of characters before and after the @ and the .


i have tried the regular expresions but these failed for us with various email address so opted for this which work in the javascript version but we now need to use this in PHP on the server side to validate before it is used.

Fou-Lu
05-31-2011, 12:01 AM
Filtervar:


function verifyEmail($sEmail)
{
return filter_var($sEmail, FILTER_VALIDATE_EMAIL);
}

if (false === verifyEmail('email@host.com'))
{
print 'invalid email.';
}

Much easier than pulling the full regexp for email addresses.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum