Genesys Cloud - Main

 View Only

Sign Up

  • 1.  How to validate customer's entered number is a proper phone number?

    Posted 10-20-2025 08:04

    Scenario: We've an use case, where we're asking customer to enter his/her phone number. After the input we want to validate whether it is a valid phone number. Because, customer can enter any digits and we cannot confirm whether it's a proper phone number or not.

    Approach: I thought to check whether it is in E.164 format to ensure the validity of the number. For that I am using this expression - !IsNotSetOrEmpty(ToPhoneNumber(Append("+", Flow.CustomerPhoneNumber)).e164). But, this check is true even if I am giving 123456 as input. I thought to use the isTel property of Phone Number data type to ensure the validity but It was not always true.

    Please suggest a way to ensure the validity of a phone number entered by customer in architect.

    Regards,

    Subhajit Podder


    #ArchitectandDesign

    ------------------------------
    Subhajit Podder
    NA
    ------------------------------


  • 2.  RE: How to validate customer's entered number is a proper phone number?

    Posted 10-20-2025 09:12

    We used to validate if user is not entering 11111111, 22222222... 12345678, and sutff like this. You'll need to check at you country if there any rules about phone numbers like 'cannot begin with 2' or 'mobile numbers must begin with 9 digit and have 9 digits lenght'. But doesn't garantee that customer is entering a valid phone number.



    ------------------------------
    Debora Lopes
    ------------------------------



  • 3.  RE: How to validate customer's entered number is a proper phone number?

    Posted 10-20-2025 09:16

    It's not specific to any country, as we have global customers across multiple regions. Is there any way to do that with existing functionalities?



    ------------------------------
    Subhajit Podder
    NA
    ------------------------------



  • 4.  RE: How to validate customer's entered number is a proper phone number?

    Posted 10-20-2025 09:24

    HI Subhajit Podder,

    Using Data Actions Functions, as I mentioned, it's possible to use the libphonenumber library, it validates phone numbers globally according to each country's numbering plan.



    ------------------------------
    Luiz Rosa
    Full stack developer
    ------------------------------



  • 5.  RE: How to validate customer's entered number is a proper phone number?
    Best Answer

    Posted 10-20-2025 09:14
    Edited by Jason Kleitz 10-21-2025 09:05

    Hi Subhajit Podder

    It really depends on what kind of validation you need. 

    In Brazil we usually check structure (DDD + number) and length first. If you have Data Actions Functions available, you can create a small Node.js code to validate the number, using a regex or, preferably, a phone validation library.

    Each country has different rules, so the logic should be adapted to the local numbering plan.


    Exemple:

    exports.handler = async (event) => {

      const rawNumber = String(event.number || '').replace(/\D+/g, '');


      const withCountry = rawNumber.startsWith('55') ? rawNumber : '55' + rawNumber;

     
      const BR_REGEX = /^(?:55)?(?:[1-9]\d)(?:9\d{8}|\d{8})$/;

      const isValid = BR_REGEX.test(withCountry);
      const e164 = isValid ? '+' + withCountry : null;

      return {
        isValid,
        e164,
        original: event.number
      };
    };


    ------------------------------
    Luiz Rosa
    Full stack developer
    ------------------------------



  • 6.  RE: How to validate customer's entered number is a proper phone number?

    Posted 9 days ago

    Thanks Luiz,

    It really helped me to figure out the solution.



    ------------------------------
    Subhajit Podder
    NA
    ------------------------------



  • 7.  RE: How to validate customer's entered number is a proper phone number?

    Posted 10-20-2025 09:19

    Hi Subhajit, 

    When I'm asking for a phone number to be input, I use a Collect Input block, and set the Input Data Name as Task.collectedANI, then in the Success path, I have a Decision block, set as an Expression, with the line:

    Length(ToString(ToPhoneNumber(Task.collectedANI)))==11

    This will then check and see if the number of digits collected is 11 and if it is then it will route down the Yes path.

    You could also do a Decision block that says:

    left(ToPhoneNumber(Task.collectedANI).subscriberNumber,1)=="3"
    OR
    left(ToPhoneNumber(Task.collectedANI).subscriberNumber,1)=="8"

    This will see if the number they entered starts with a 3 or 8 (premium numbers for instance), and route accordingly, or you could have it as:

    left(ToPhoneNumber(Task.collectedANI).subscriberNumber,1)=="7"

    to ensure it is a mobile number etc. 

    These are just some ideas you could try out.

    The IsNotSetOrEmpty is checking to see if Flow.CustomerPhoneNumber has had anything entered. This would only be Yes if the customer did not enter any digits

    The ToPhoneNumber is converting the value to a phone number, so your 123456 is already being converted to a phone number, which will be why your validity is true. 



    ------------------------------
    Martin Boyle
    x
    ------------------------------