Skip to content

Instantly share code, notes, and snippets.

@pelusium
Created January 11, 2017 14:57
Show Gist options
  • Save pelusium/77cbf5c63da3a834d779d8047007f451 to your computer and use it in GitHub Desktop.
Save pelusium/77cbf5c63da3a834d779d8047007f451 to your computer and use it in GitHub Desktop.
Validate Name PT
jQuery.validator.addMethod('isValidName', function(value, element) {
var regex = /(^([ A-Za-zá-úÁ-Ú.\s]){1,200})+$/;
var names = rtrim(value).split(' ');
var test = true;
if( names.length <= 1 ){
test = false;
}else{
for( var k=0; k< names.length; ++k ){
if( !regex.test( names[k] ) ){
test = false;
}
}
}
return this.optional(element) || test && !formValidation_isInvalidName(value)
});
function formValidation_isInvalidName( param_name ){
var invalidName = ['aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii','jjj','kkk','lll','mmm','nnn','ooo','ppp','qqq','rrr','sss','ttt','uuu','vvv','www','xxx','yyy','zzz'];
for( var i=0; i < invalidName.length; ++i ){
if( param_name.indexOf(invalidName[i]) > -1 ) return true;
}
return false;
}
function rtrim ( s ){return s.replace( /\s*$/, '' );}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment