Created
February 21, 2010 02:15
-
-
Save evadne/310065 to your computer and use it in GitHub Desktop.
monoValidate (yup, with an easter egg)
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
// monoValidate.js by Evadne Wu, this version retrieved 2010. 02. 21. New BSD. | |
// Library required: jQuery. Evadne is reachable thru monoceroi.com. | |
// Notice: malformed URIs galore and our URI schema has not been tested against with many real-world cases yet. | |
function monoValidate(stringToBeValidated, proposedCategory) { | |
// So we can leniently call monoValidate to validate against nothing; that way everything that is not required to be validated is valid | |
if (stringToBeValidated == '' || proposedCategory == '') return true; | |
var options = $.extend({ | |
'caseSensitive': false | |
}, arguments[2]); | |
var schemata = { | |
'email': new RegExp(/[a-z0-9!#$%&'*+//=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+//=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2}||se|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|local)\b/), | |
'uri': new RegExp(/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/) | |
} | |
if (!options.caseSensitive) stringToBeValidated = String(stringToBeValidated).toLowerCase(); | |
if (schemata[String(proposedCategory)] == undefined) return false; | |
return (String(stringToBeValidated).match(schemata[String(proposedCategory)]) != null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment