Skip to main content



No record found.

Dynamics 365 Community / Forums / Sales forum / URL validation using R...
Sales forum

URL validation using RegEx works in Main form but not in Quick Create

Posted on by 102
I have created the following JavaScript to validate a URL in a URL field on a form then throw an error if the URL is invalid.  I am also
preventing the form from saving if the URL is invalid.  This all works great in the main PowerApps form:
function validateURL() {    var fieldVal = Xrm.Page.getAttribute(/xx_url/).getValue();       var urlPattern = /^https?://////[^//s///$?#]+//.[^//s]*$/;    if (urlPattern.test(fieldVal)) {        // Valid URL        Xrm.Page.ui.clearFormNotification(/urlValidation/);        return true; // Allow the form to save    } else {        // Invalid URL        Xrm.Page.ui.setFormNotification(/Invalid URL!/, /ERROR/, /urlValidation/);        return false; // Prevent the form from saving    }}function onSavePreventInvalidURL() {    if (!validateURL()) {;    }}function validateCancel(executionContext) {    var saveEvent = executionContext.getEventArgs();    saveEvent.preventDefault(); // Cancel the form save action}// Register onSavePreventInvalidURL as a handler for the /OnSave/;


But when I apply the same code to the Quick Create form for the same
table in the same way, the code works for valid URLs but not for invalid

  • An error is displayed (correctly)
  • The form does not save (correctly)
  • When the URL is corrected, the Error dissapears (correctly)
  • But the form will not save (incorrectly)

One suggestion was that the Quick Create form may use /states/ differently
to the main form but I really don't know what that means or how it may
affect a fairly simple bit of JavaScript which is working well on the
main form.

I'm relatively new to this so don't know what I am missing.  Any ideas? 



Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans