Bug #179
Registration JS email validator accept extra @
| Status: | Closed | Start date: | 02/12/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | D B | % Done: | 100% |
|
| Category: | Registration | |||
| Target version: | 1.4.5 | |||
| Reproducibility: | Database Type: | |||
| Reported In MyBB Version: | Database Version: | |||
| PHP Version: | SQA assignments: | |||
| Browser: |
Description
In the server side everything work as expected but the JS validator accept also email like this "my@name@host.com".
http://community.mybboard.net/thread-45103.html - Extra @ in valid email
test case:
[quote='dvb' pid='310725' dateline='1234471351']
open the firebug console and copy&paste the following:
[code]
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@name@host.com";
console.log("1: " + regex1.test(str))
console.log("2: " + regex2.test(str))
[/code]
This will print:
[quote]
1: false
2: true
[/quote]
Although, the regexes are supposed to be the same.
Of course as you can understand MyBB using the second method ("new RegExp")
[/quote]
Solution:
[quote='dvb' pid='310757' dateline='1234475425']
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:
[code]
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}'});
[/code]
replace it with the line:
[code]
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}'});
[/code]
[/quote]
Associated revisions
Fixes Registration JS email validator accept extra @ (fixes: 179)
History
#1 Updated by D B over 3 years ago
- File registration_email_js_validator.patch added
- % Done changed from 80 to 100
done, patch attached
#3 Updated by D B about 3 years ago
- File deleted (
registration_email_js_validator.patch)
#4 Updated by Chris W. B. about 3 years ago
- Status changed from Resolved to Closed