Skip to main content

Notifications

Announcements

No record found.

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

  • Sri College Profile Picture
    Sri College 45 on at
    RE: Validate the Website Url field using javascript in dynamics crm

    Thank you Mehran.

  • Suggested answer
    MehranBre Profile Picture
    MehranBre 730 on at
    RE: Validate the Website Url field using javascript in dynamics crm

    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
    Sri College 45 on at
    RE: Validate the Website Url field using javascript in dynamics crm

    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

  • Verified answer
    MehranBre Profile Picture
    MehranBre 730 on at
    RE: Validate the Website Url field using javascript in dynamics crm

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,317 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans