Skip to content

Instantly share code, notes, and snippets.

@MikeiLL
Created October 8, 2016 15:20
Show Gist options
  • Save MikeiLL/cfc26649751cf0336d51e3debd58b2c6 to your computer and use it in GitHub Desktop.
Save MikeiLL/cfc26649751cf0336d51e3debd58b2c6 to your computer and use it in GitHub Desktop.
Bootstrap FormValidation Domain Name or IP address
$('#domainName').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
ip: {
validators: {
callback: {
message: 'The address is not valid',
callback: function(value, validator, $field) {
// Check the password strength
var ipAddress = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.exec(value);
var domainNameURL = /^(?!:\/\/)([a-zA-Z0-9]+\.)?[a-zA-Z0-9][a-zA-Z0-9-]+\.[a-zA-Z]{2,6}?$/i.exec(value);
if ((!ipAddress) && (!domainNameURL)){
return {
valid: false,
message: 'Must be a fully qualifying Domain Name or IP address'
};
}
if ((ipAddress) && (typeof(ipAddress) !== 'undefined')){
if ((ipAddress[0] != value)){
return {
valid: false,
message: 'Must be a fully qualifying Domain Name or IP address'
};
}
return true;
}
if ((domainNameURL) && (typeof(domainNameURL) !== 'undefined')) {
if ((domainNameURL[0] != value)){
return {
valid: false,
message: 'Must be a fully qualifying Domain Name or IP address'
};
}
return true;
}
return true;
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment