web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

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

(1) ShareShare
ReportReport
Posted on by 20
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()) {        Xrm.Page.data.entity.addOnSave(validateCancel);    }}function validateCancel(executionContext) {    var saveEvent = executionContext.getEventArgs();    saveEvent.preventDefault(); // Cancel the form save action}// Register onSavePreventInvalidURL as a handler for the /OnSave/ eventXrm.Page.data.entity.addOnSave(onSavePreventInvalidURL);

 

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
URLs:

  • 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? 

 

 
 
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 92 Super User 2026 Season 2

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 35 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 34 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans