web
You’re offline. This is a read only version of the page.
close
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

How can i create a error message through label using javascript in CRM

(1) ShareShare
ReportReport
Posted on by 45

i was create phone number validation on quick create account in CRM

how can i display a  error message through label using javascript in CRM

Can you please help any one. 

My Code: 
----------

function Phonevalidation() {

var phoneCleaned;

var phoneNumber = Xrm.Page.getAttribute("telephone1");

if (phoneNumber.getValue() != null) {

phoneCleaned = phoneNumber.getValue().replace(/[^0-9]/g, "");

if (phoneCleaned.length !== 10) {

alert(" must contain 10 numbers.");

Xrm.Page.getAttribute("telephone1").setValue(null);

return false;
}
phoneNumber.setValue("(" + phoneCleaned.substr(0, 3) + ") " + phoneCleaned.substr(3, 3) + "-" + phoneCleaned.substr(6, 4));
}
return true;
}



Thank you

I have the same question (0)
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Sree,

    Try setNotification method.

    Xrm.Page.getControl("telephone1").setNotification("Please type phone number in correct format");

    However, the notification will render as tooltip in classic web client.

    pastedimage1615281715999v1.png

    While in UCI, it is changed to label with error message.

    pastedimage1615281998803v2.png

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setnotification

    https://neilparkhurst.com/2015/11/02/javascript-notifications/

  • Sri College Profile Picture
    45 on at

    Thank you for your answer Clofly ......

    I have one more question

    how to do a validation for us phone number not to begin with 0 or 1?

    Can you please help me

  • cloflyMao Profile Picture
    25,210 on at

    Hi Sree,

    Try following code:

    var pattern1 = /^0/;
    
    var pattern2 = /^1/;
    
    var phoneNumber = Xrm.Page.getAttribute("telephone1").getValue();
    
    var found = pattern1.test(phoneNumber) || pattern2.test(phoneNumber);
    
    console.log(found);

    If the phone number not begins with 0 or 1, then the found variable will be false.

    pastedimage1615359862505v1.png

    Reference:

    https://stackoverflow.com/questions/26068100/validate-u-s-phone-numbers-only

  • cloflyMao Profile Picture
    25,210 on at

    Hi Sree,

    Please let me know whether the solution could work for you. :)

  • Sri College Profile Picture
    45 on at

    Thank you Clofly

    sorry for late reply.

    I will check your code then update to you.

    I am using this below line for mobile number do not begin with zero 

    var regex = /^(?:[1-9][0-9]*)$/;

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans