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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Validate the Website Url field using javascript in dynamics crm

(0) ShareShare
ReportReport
Posted on by 45

Hello 

Validate the Website Url field using  javascript in dynamics crm. 


How can i implement this one validation

Can u please help me. 

Thank you

I have the same question (0)
  • Verified answer
    MehranBre Profile Picture
    732 on at

    Hi,

    add this function to OnChange Event of field:

    function OnChangeWebSite() {
    
        var webSite = Xrm.Page.getAttribute("webSite");
    
        if (webSite.getValue() != null) {
    
            if (!validURL(webSite.getValue())) {
    
                alert("Please Insert a Valid URL!");
            }
        }
    }
    
    function validURL(str) {
        var pattern = new RegExp('^(https?:\\/\\/)?'   // protocol
            '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.) [a-z]{2,}|'   // domain name
            '((\\d{1,3}\\.){3}\\d{1,3}))'   // OR ip (v4) address
            '(\\:\\d )?(\\/[-a-z\\d%_.~ ]*)*'   // port and path
            '(\\?[;&a-z\\d%_.~ =-]*)?'   // query string
            '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
        return !!pattern.test(str);
    }

    Best Regards.

  • Sri College Profile Picture
    45 on at

    Thank you Mehran.

    Very nice update. It is very useful to me.

    Your code output displays like this: https://test.in

    I need like this format :https://www.test.in

    Can u pls help me

  • Suggested answer
    MehranBre Profile Picture
    732 on at

    ok, use this:

    function validURL(str) {
    
        var pattern = new RegExp(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\ ~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\ .~#?&\/\/=]*);
        return !!pattern.test(str);
    }

    Regards.

  • Sri College Profile Picture
    45 on at

    Thank you Mehran.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans