Skip to content

Instantly share code, notes, and snippets.

@pelusium
Last active January 11, 2017 14:55
Show Gist options
  • Save pelusium/0774c858ef9eff5f7dcccef30602e93d to your computer and use it in GitHub Desktop.
Save pelusium/0774c858ef9eff5f7dcccef30602e93d to your computer and use it in GitHub Desktop.
Regex telefone PT
jQuery.validator.addMethod('isValidPhoneNumber', function(value, element) {
var regex = new RegExp('^[0-9]{9}$');
var isValid = true;
if(value.charAt(0) != 2 && value.charAt(0) != 3 && value.charAt(0) != 9 ) isValid = false;
if( (value.charAt(0) == 9) && (value.charAt(1) != 6 && value.charAt(1) != 1 && value.charAt(1) != 3 && value.charAt(1) != 2 && value.charAt(1) != 4)) isValid = false;
if (value.charAt(0) == 3 && value.charAt(1) == 5 && value.charAt(2) == 1) isValid = false;
if(formValidation_isInvalidPhoneNumbers(value)) isValid = false;
return this.optional(element) || (regex.test(value) && isValid)
});
function formValidation_isInvalidPhoneNumbers( phone ){
var invalidPhones = ['222222222','211234567','961234567','911234567','912345678','931234567','921234567','960000000','961111111','962222222','963333333','964444444','965555555','966666666','967777777','968888888','969999999','910000000','911111111','912222222','913333333','914444444','915555555','916666666','917777777','918888888','919999999','930000000','931111111','932222222','933333333','934444444','935555555','936666666','937777777','938888888','939999999','920000000','921111111','922222222','923333333','924444444','925555555','926666666','927777777','928888888','929999999','210000000','211111111','212222222','213333333','214444444','215555555','216666666','217777777','218888888','219999999','969696969','910101010','333333333'];
for( var i=0; i < invalidPhones.length; ++i ){
if( phone == invalidPhones[i] ) return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment