Created
July 8, 2015 17:03
-
-
Save vctrfrnndz/8976fd1b717230bfd851 to your computer and use it in GitHub Desktop.
input validations
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
function inputValidations() { | |
function isAlphaNumeric(val) { | |
var letter = /[a-zA-Z]/, | |
number = /[0-9]/; | |
var valid = number.test(val) && letter.test(val); | |
return valid; | |
} | |
function isMinLength(val, min) { | |
if(val.length >= min) { | |
return true; | |
} | |
return false; | |
} | |
function isMaxLength(val, max) { | |
if(val.length <= max) { | |
return true; | |
} | |
return false; | |
} | |
function isNumber(val) { | |
if(!val.match(/^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/)) { | |
return true; | |
} | |
return false; | |
} | |
function isPhoneNumber(val) { | |
if(val.match(/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/)) { | |
return true; | |
} | |
return false; | |
} | |
function containsNumbers(val) { | |
if(val.match(/\d+/g)) { | |
return true; | |
} | |
return false; | |
} | |
function isInt(val) { | |
if(!val.match(/^[+-]?\d+(\\d+)?([eE][+-]?\d+)?$/)) { | |
return true; | |
} | |
return false; | |
} | |
function isValidEmail(val) { | |
if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(val)) { | |
return true; | |
} | |
return false; | |
} | |
function isEmpty(val) { | |
if(!$.trim(val).length) { | |
return true; | |
} | |
return false; | |
} | |
return { | |
isEmpty: isEmpty, | |
isInt: isInt, | |
isValidEmail: isValidEmail, | |
isNumber: isNumber, | |
isPhoneNumber: isPhoneNumber, | |
isAlphaNumeric: isAlphaNumeric, | |
containsNumbers: containsNumbers, | |
isMinLength: isMinLength, | |
isMaxLength: isMaxLength | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment