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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM c# match a phone number ignoring characters [A-Z] and special characters

(0) ShareShare
ReportReport
Posted on by 505

Hello,

I want to retrieve leads matching a phone number but ignoring characters and special characters.

For example if a phone number to match is "234567890" and the phone number on lead is "abc234?>*-;567890" , then my query expression should retrieve this lead.

How can I achieve this using query expression?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    Hello,

    You can add a Condition .AddCondition("phonenumber, ConditionOperator. Contains, "your value")

    docs.microsoft.com/.../gg327700(v%3Dcrm.8)

    Hope this helps,

    Radu

  • Priyank Bhavsar Profile Picture
    505 on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    Contains operator doesn't work for me because numeric characters can be at any position in the string.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    Hi Priyank,

    Try with this -

                            QueryExpression qe = new QueryExpression();
                            string AnyValue = "34534534";
                            string phonenumber = "%" + AnyValue + "%";
                            ConditionExpression condition1 = new ConditionExpression();
                            condition1.AttributeName = "phonenumber";
                            FilterExpression filter1 = new FilterExpression();
                            condition1.Operator = ConditionOperator.Like;
                            condition1.Values.Add(phonenumber);
                            filter1.Conditions.Add(condition1);
                            qe.Criteria.AddFilter(filter1);


  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    Hi,

    I don't think you can use RegEx within the conditonexpression. However you can retrieve all records and then apply LINQ & RegEx to retrieve the desired records. Something like mentioned in this thread-

    stackoverflow.com/.../how-do-i-search-for-lead-or-account-using-dynamics-crm-sdk

    Hope this helps.

  • Suggested answer
    Daniel Wikell Profile Picture
    2,360 on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    I would add some validation to ensure that phone numbers can't be entered like that in the first place.

    If you for some reason want to keep allowing phone numbers to have odd special characters or if this is an attempt at locating and cleaning up data after the introduction of some validation you can pretty much only accomplish this by duplicating the phone number field to a different field, with cleaned out characters. This way you can instead query your other field that only contain the digits of the phone number.

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: CRM c# match a phone number ignoring characters [A-Z] and special characters

    Hi,

    This helps you,

    var input = "abc234?>*-;567890";
    var result = String.Join("", input.Where(c => Char.IsDigit(c) || c == '.'));
    Console.WriteLine(result);

    Thanks,

    Sreevalli

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans