Created
October 8, 2016 15:20
-
-
Save MikeiLL/cfc26649751cf0336d51e3debd58b2c6 to your computer and use it in GitHub Desktop.
Bootstrap FormValidation Domain Name or IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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