History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: FMNG-12
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Dan Hardiker
Reporter: Simon Wheatley
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Confluence Extension: Form Mail NG

Email addresses containing a space pass validation

Created: 23/May/07 08:32 AM   Updated: 02/Feb/08 08:17 PM
Component/s: None
Affects Version/s: 1.0.3
Fix Version/s: 1.1

Time Tracking:
Not Specified


 Description  « Hide
This email address passes validation, but shouldn't: contains.space @example.com

The space must be on the left of the @ sign to sneak past the validation. (Spaces on the right of the @ are correctly interpreted as invalid.)

This error exists in the admin console and the end user email validation.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Dan Hardiker - 02/Feb/08 05:17 PM
The logic is as follows, feel free to suggest improvements!
isEmail: function (str) {
    // If regular expressions aren't supported
    if (!FormMailNGUtil.regexSupported())
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    // If they are
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}

Simon Wheatley - 02/Feb/08 05:28 PM
My regex-fu is far too weak to critique meaningfully, sorry. From my limited understanding of email validation regexes, your proposal looks fairly complete, but by no means (as I understand it) definitive.

Dan Hardiker - 02/Feb/08 08:16 PM - edited
I think it would be much simpler to add a check to make sure spaces aren't used! It looks like this now:
isEmail: function (str) {
    // Check to see if it contains a space
    if (str.indexOf(" ") > -1) return false;
    // If regular expressions aren't supported
    if (!FormMailNGUtil.regexSupported())
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    // If they are
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}