Created
September 27, 2023 17:27
-
-
Save relipse/5b8646cd3da6898f049e12fde717464a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Generate an array of English requirements from the html element validation | |
* @param $element | |
* @returns {*[]} | |
*/ | |
const generateRequirementsFromHtmlValidation = function($element){ | |
var min = null; | |
var max = null; | |
var minlength = null; | |
var maxlength = null; | |
var pattern = null; | |
var requirements = []; | |
if ($element.attr('required')){ | |
requirements.push('required'); | |
} | |
if ((min = $element.attr('min')) !== undefined){ | |
requirements.push('a minimum of '+min); | |
} | |
if ((max = $element.attr('max')) !== undefined){ | |
requirements.push('a maximum of '+max); | |
} | |
if ((minlength = $element.attr('minlength')) !== undefined){ | |
requirements.push('a minimum length of '+minlength); | |
} | |
if ((maxlength = $element.attr('maxlength')) !== undefined){ | |
requirements.push('a maximum length of '+maxlength); | |
} | |
if ((pattern = $element.attr('pattern')) !== undefined){ | |
requirements.push('has a regular expression of "'+pattern+'"'); | |
} | |
return requirements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment