Skip to content

Instantly share code, notes, and snippets.

@dennishall1
Created March 3, 2016 17:29
Show Gist options
  • Save dennishall1/5f244663602c31f66494 to your computer and use it in GitHub Desktop.
Save dennishall1/5f244663602c31f66494 to your computer and use it in GitHub Desktop.
// http://docs.jquery.com/Plugins/Validation/Methods/email
email: function(value, element) {
// contributed by Dennis Hall
// simplified enough for ff2 to not choke
return this.optional(element) || /^\s*[^ <>]+@[^ <>]+\.[a-z]{2,9}\s*$/i.test(value);
},
email_multiple: function(value, element) {
// contributed by Dennis Hall
// simplified enough for ff2 to not choke
var length = value.length,
indexOfSeparator = -1,
isValid = true;
///
for(var i=0;i<length;i++){
var ch = value.charAt(i);
if( ch == ',' || ch == ';' || i == length-1){
isValid = isValid && /^\s*[^ <>]+@[^ <>]+\.[a-z]{2,9}\s*$/i.test(value.substring(indexOfSeparator+1, (i==length-1?length:i)));
indexOfSeparator = i;
}
}
return this.optional(element) || isValid;
},
phone3: function(value, element) {
// contributed by Dennis Hall
// first field must be of the form "<field name id>-1", and other 2 fields must be of the form "<field name id>-2", "<field name id>-3"
var idBase = element.id.replace(/-1$/,''),
values = [value, $('#'+idBase+'-2').val(), $('#'+idBase+'-3').val()],
requiredLengths = [3,3,4];
///
for(var i=0;i<3;i++){
if(!/^\d+$/.test(values[i]) || values[i].length != requiredLengths[i]){
return false;
}
}
return true;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment