Skip to content

Instantly share code, notes, and snippets.

@byjml
Created October 4, 2012 13:36
Show Gist options
  • Save byjml/3833565 to your computer and use it in GitHub Desktop.
Save byjml/3833565 to your computer and use it in GitHub Desktop.
Wildcard DNS validation regex.
<?php
/**
* Uses a simple regex to validate a wildcard DNS format.
*
* It validates the following entry formats:
* *.example.com.
* *.exa.m.ple.com.
* *.exa-mp.le.com.
* *.ex--ample.com.
*/
function validate_wildcard_dns( $entry ) {
if ( preg_match( '/^(\\*\\.)+([a-z0-9]([-a-z0-9]*[a-z0-9])?\\.)+([a-z]{2,6})+(\\.)$/i', $entry ) ) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment