Domain Mapping Validation

We noticed that the domain mapping plugin doesn’t have any sort of validation on entering the domain name to be added on the settings page. We’ve created some javascript (jQuery) to make sure users don’t add erroneous domains to their blogs, disabling them in the process. It’s written as a plugin so it can be run independently from the plugin, enabling it to work even after a plugin update.

add_action( 'admin_footer', 'custom_domain_validation' );

function custom_domain_validation() {
?>
<script type="text/javascript">
jQuery("#the-list input[type='submit']").click(function(){
// Input text must have at least one period, the last letter cannot be a period and can only include uppercase and lowercase letters and numbers
if ((jQuery("#the-list input[name='domain']").val().match("^[A-Za-z0-9._]*[A-Za-z0-9][A-Za-z0-9._]*$") === null) || (jQuery("#the-list input[name='domain']").val().indexOf(".") === -1) || (jQuery("#the-list input[name='domain']").val().substring(jQuery("#the-list input[name='domain']").val().length,jQuery("#the-list input[name='domain']").val().length -1) === ".")){
alert("Sorry, you've typed an invalid domain name. Please try again.");
return false;
}
var r = confirm("Press OK to confirm that you would like to add this domain to your blog. If the domain is entered incorrectly, your blog may no longer work as expected.");
if (r != true){ return false; }
});
</script>
<?php
}

  • aristath
    • Recruit

    Hello there @ed Cooper,

    Wow, thanks a lot for the contribution!

    I have the feeling this will prove useful to a lot of people… :slight_smile:

    I’ve sent some re points your way and also tagged the plugin developer on this issue so that he may see it as well. :slight_smile:

    Take care,

    Ari.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.