-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2886 from webcompat/issue/2725/2
Fixes #2725: Bugform validation improvements
- Loading branch information
Showing
9 changed files
with
324 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* exported Validation */ | ||
function Validation() { | ||
var GITHUB_REGEXP = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i; | ||
var ALLOWED_IMG_FORMAT = ["jpg", "jpeg", "jpe", "png", "gif", "bmp"]; | ||
|
||
var isReportableURL = function(url) { | ||
var ok = url && (_.startsWith(url, "http:") || _.startsWith(url, "https:")); | ||
ok &= !(_.startsWith(url, "http:// ") || _.startsWith(url, "https:// ")); | ||
return ok; | ||
}; | ||
|
||
/** | ||
Check a string is a valid GitHub username | ||
- maximum 39 chars | ||
- alphanumerical characters and hyphens | ||
- no two consecutive hyphens | ||
*/ | ||
var isValidGitHubUsername = function(contact) { | ||
return GITHUB_REGEXP.test(contact); | ||
}; | ||
|
||
return { | ||
isDescriptionValid: function(descField) { | ||
var val = descField.val(); | ||
return $.trim(val) !== ""; | ||
}, | ||
isUrlValid: function(urlField) { | ||
var val = urlField.val(); | ||
return $.trim(val) !== "" && isReportableURL(val); | ||
}, | ||
isGithubUserNameValid: function(contactField) { | ||
var contact = contactField.val(); | ||
return isValidGitHubUsername(contact) || $.trim(contact) === ""; | ||
}, | ||
isProblemTypeValid: function(problemTypeField) { | ||
return problemTypeField.filter(":checked").length; | ||
}, | ||
isImageTypeValid: function(uploadField) { | ||
var splitImg = uploadField.val().split("."); | ||
var ext = splitImg[splitImg.length - 1].toLowerCase(); | ||
|
||
return _.includes(ALLOWED_IMG_FORMAT, ext); | ||
}, | ||
isOptionalValid: function(input) { | ||
return !!input.val(); | ||
} | ||
}; | ||
} |
Oops, something went wrong.