/**
* Validate Belgium 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 = [
/^((\+|00)32\s?|0)(\d\s?\d{3}|\d{2}\s?\d{2})(\s?\d{2}){2}$/,
/^((\+|00)32\s?|0)4(60|[789]\d)(\s?\d{2}){3}$/
];
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 Belgium 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.