MyBB Community Forums

Full Version: [F] Extra @ in valid email [R] [C-Chris]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MyBB doesn't accept 2 @ chars in an email, as it should. However, the AJAX check, marks it as valid (in other words, having two @ chars in an email marks the field green).

I tried an invalid email like so:
fdf@[email protected]

And it highlighted the email field green. However, having an email like so: goooggglglg@@google.com is invalid.

It's nothing major, but it pretty much defeats the purpose of the AJAX check validation for easy registration.
Best Regards.
The regexp seems to be ok...
/^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/

UPDATE:
Strange.... I'm not so good in js, so maybe someone else will be able to explain this:

open the firebug console and copy&paste the following:
regex1 = /^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

regex2 = new RegExp('^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$');

str = "my@[email protected]";

console.log("1: " + regex1.test(str))
console.log("2: " + regex2.test(str))
This will print:
Quote:1: false
2: true
Although, the regexes are the same.
Of course as you can understand MyBB using the second method ("new RegExp")
Shouldn't this:

/^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/

Be this:
/!^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$!/

That will make it strict and it should work.
oh... it has nothing to do with the regexes, nor nothing special to javascript... it's the slashes!
in the first method ( /theregex/ ), the slashes are part of the regex, they're used to escape literal chars into the regex
BUT
in the second method ( new RegExp('theregex') ), the slashes between the apostrophes are used to escape special chars into the string like '\r\n\t'

THE SOLUTION:
while using the second method every slash should be doubled so the first one used to escape the second into the string and the second slash will escape the literal char into the regex

In the ACP open the template 'member_register', scroll down and find the following line:
	regValidator.register('email', 'regexp', {match_field:'email2', regexp:'^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$', failure_message:'{$lang->js_validator_invalid_email}'});
replace it with the line:
	regValidator.register('email', 'regexp', {match_field:'email2', regexp:'^([a-zA-Z0-9_\\.\\+\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$', failure_message:'{$lang->js_validator_invalid_email}'});

Can someone just validate this again?

Also someone should search any other place in MyBB that this problem might occur again
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group
Solution is confirmed to work. All what's left is to have a developer update the revision, then I'll confirm the thread.