Formula using regex to identify letter in phone number not working correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jesse
    Junior Member
    • Nov 2021
    • 1

    Formula using regex to identify letter in phone number not working correctly

    Hello everyone,

    I am trying to get a formula to work in the Formula field in the Entity Manager, that should output a 1 or 0, depending on whether or not there is a letter in the phone number field.

    This is the formula I'm trying to use:

    Code:
    ifThenElse(string\test(phoneNumber, '.*[a-zA-Z].*'), leadContainsPhoneNumber=0, leadContainsPhoneNumber=1);
    The field 'phoneNumber' is of the type 'Phone' and typically includes number strings, but sometimes also letters or a phrase like 'not provided'.
    A second field, 'leadContainsPhoneNumber', which is a Boolean (checkbox that should be checked if output is 'TRUE' (or 0) and unchecked if output is 'FALSE' (or 1).
    The expression should check if the string in the field phoneNumber contains any letter from a-z (or lower or uppercase). However, for some reason, the box in the records is always checked, even if letters are present. I cannot figure out if something in the syntax is incorrect, or if I am overlooking something relevant here.

    Does anybody have an idea what might be wrong, or how to solve it?
  • esforim
    Active Community Member
    • Jan 2020
    • 2204

    #2
    My regex is basically search copy on the internet.

    My personally suggestion for you to make this work is to start simply with your formula. Why don't you start out with a "check for number 5" first? For example:

    string\test(phoneNumber, '5')

    And test to see if it work, then go from there then slowly doing a simple letter, like 'a'. If it doesn't work then it too early to worry about 'a-zA-Z'

    Comment

    • noahharold
      Junior Member
      • Sep 2024
      • 1

      #3
      Originally posted by Jesse
      Hello everyone,

      I am trying to get a formula to work in the Formula field in the Entity Manager, that should output a 1 or 0, depending on whether or not there is a letter in the phone number field.

      This is the formula I'm trying to use:

      Code:
      ifThenElse(string\test(phoneNumber, '.*[a-zA-Z].*'), leadContainsPhoneNumber=0, leadContainsPhoneNumber=1);
      rice purity test

      The field 'phoneNumber' is of the type 'Phone' and typically includes number strings, but sometimes also letters or a phrase like 'not provided'.
      A second field, 'leadContainsPhoneNumber', which is a Boolean (checkbox that should be checked if output is 'TRUE' (or 0) and unchecked if output is 'FALSE' (or 1).
      The expression should check if the string in the field phoneNumber contains any letter from a-z (or lower or uppercase). However, for some reason, the box in the records is always checked, even if letters are present. I cannot figure out if something in the syntax is incorrect, or if I am overlooking something relevant here.

      Does anybody have an idea what might be wrong, or how to solve it?
      It looks like there might be an issue with how you're using the ifThenElse function. The logic seems inverted. Try reversing the outputs:
      plaintext
      Copy
      ifThenElse(string\test(phoneNumber, '.*[a-zA-Z].*'), leadContainsPhoneNumber=1, leadContainsPhoneNumber=0);
      This way, if a letter is found, it should set leadContainsPhoneNumber to 1 (checked), and if not, it will set it to 0 (unchecked). Give this a try!

      Comment

      • shalmaxb
        Senior Member
        • Mar 2015
        • 1603

        #4
        two advices:
        boolean in formula is true or false not 1 and 0
        formatting the formula is helpful this way:

        Code:
        ifThenElse(
                 if-part,
                 then-part,
                 else-part
        );
        This helps to not oversee mistakes.

        Comment

        Working...