Created
September 27, 2016 08:09
-
-
Save sayanriju/9fcc6fd0405de9eb1044a5ff997437c8 to your computer and use it in GitHub Desktop.
A collection of simple validators for using with html forms
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
var validateEmail = function (email) { | |
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
return re.test(email); | |
} | |
var validateAlphanumeric = function (txt) { | |
var re = /^[a-z0-9]*$/i; | |
return re.test(txt); | |
} | |
var validateNumeric = function (txt) { | |
var re = /^[0-9]*$/i; | |
return re.test(txt); | |
} | |
var validateLength = function (txt, len) { | |
return (txt.length === len); | |
} | |
var validateRequired = function (txt) { | |
return (txt !== undefined && txt !== null && txt.trim() !== ""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment