You should be able to use the GlobalPageValidation.ValidateExternalURL event handler to do this (just create a new PageValidateEventArgs with your new page inside, call the handler with it and then check the EventArgs' IsValid property).
Could be it doesn't work for an unsaved page, I haven't tried. Post a reply if you get it working :)
All the ValidateExternalURL seems to do is making upper case characters to lower case. I can still save the page with an allready "occupied" PageExternalURL. As a little side note it also allows characters like €%&, while the function used in edit mode only allows a-z, 0-9, -, _ and ~.
I did a quick test and it seems to do exacly what is expected. This is the test code I used:
var page = DataFactory.Instance.GetDefaultPageData(PageReference.StartPage, 3);
page.PageName = "Test";
page["PageExternalURL"] = "test"; // An already used simple address
var args = new PageValidateEventArgs(page);
var isValid = args.IsValid; // false
I also tried an unused but illegal address ("#foo") and that also yields IsValid = false. The EventArgs also carries an errormessage describing the error correctly.
I'm creating pages in code and it looks like there is no built in function to check if a PageExternalURL already is used on another page. In edit mode there is a check for this but I'm now trying to find out what the best way would be to test this before saving the page.
I tried with the code below but I don't really know if this would be a satisfying way to go about. I don't seem to get any results in the PageDataCollection I get in return.
static public PageDataCollection FindPagesOfPageType(EPiServer.Core.PageReference pageLink, string pageExternalUrl)
PropertyCriteriaCollection criterias = new PropertyCriteriaCollection();
PropertyCriteria criteria = new PropertyCriteria();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Name = "PageExternalURL";
criteria.Type = EPiServer.Core.PropertyDataType.String;
criteria.Value = pageExternalUrl;
criteria.Required = true;
return DataFactory.Instance.FindPagesWithCriteria(pageLink, criterias);