Skip to content

Instantly share code, notes, and snippets.

@kladov
Created August 31, 2013 10:50
Show Gist options
  • Save kladov/6397518 to your computer and use it in GitHub Desktop.
Save kladov/6397518 to your computer and use it in GitHub Desktop.
validate something in javascript
function Validate () {
this.byValidatorsArray = function(value, validators) {
var result = true;
var arrayLength = validators.length;
for(var i = 0; i < arrayLength; i++) {
if(!this[validators[i]](value)) {
result = false;
}
}
return result;
}
this.email = function(email) {
var regExp = /^(([^<>()[\]\\.,;:\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 regExp.test(email)
}
this.notEmpty = function(value) {
return value ? true : false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment