/**
* Validate Dutch phonenumber with jQuery validator plugin
*
* @author Chris - http://codepad.co/cheers | https://github.com/webremote
* @copyright Copyright (c) 2016
* @version 0.0.1
* @build 20160209
*/
$(function(){
var formName = '#theFormID';
var fieldName = 'phonenumber';
$.validator.addMethod("telefoon", function(value, element) {
var validators = [
/^(((\\+31|0|0031)6){1}[-]?[1-9]{1}[0-9]{7})$/i,
/^(((0)[1-9]{2}[0-9][-]?[1-9][0-9]{5})|((\\+31|0|0031)[1-9][0-9][-]?[1-9][0-9]{6})|((\\+31|0|0031)[1-9]{2}[0-9][-]?[1-9][0-9]{5}))$/,
/^([\+]?31|0){1}[0-9]{1,3}[-]?[0-9]{6,8}$/,
/^(\+|00|0)(31\s?)?(6[\s-]?[1-9][0-9]{7}|[1-9][0-9][\s-]?[1-9][0-9]{6}|[1-9][0-9]{2}[\s-]?[1-9][0-9]{5})$/
];
var testValue = value.replace(/ /g, '');
$.each(validators, function(k, v) {
var pattern = v;
var result = pattern.test(testValue);
if (result) {
return false;
}
});
return true;
}, "Ongeldige telefoonnummer"); // Add custom error translation here
$(formName + ' input[name="' + fieldName + '"]').rules("add", {telefoon: true});
});
Validate multiple formats for Dutch phonenumbers with the jQuery Validator plugin
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.