·
Added a discussion to , Community

Hello UNA Team,

I am setting up a country-specific community / localized website (U.S. Region only) and I am trying to use a Regular Expression in the Phone Input Field (Create Account, Edit Account, Phone Confirmation, Log in - Step 2 / 2FA page).

I definately need to check and allow U.S. mobile numbers only. Only U.S. users will be allowed to create an account. Checking the Phone number is probably the most effective way to restrict the account creation to a specific region.

When setting up the Regex, I have discovered 2 bugs. @Alex T⚜️, @Anton L, @LeonidS, @Roman L

BUG 1:

The Regular Expression option of the Phone field doesn't work at all. 

No matter what regex you put in there, it just doesn't work. When you submit the form, it keeps on giving the default error:

Wrong phone number, allowed digits only and start from '+'

I have been testing it with the following Regex:

^\+[1]\d{10}$

This is a valid and working regex. It forces users to enter the '+' sign, the number '1' (which the U.S. country code) and the 10-digits phone number (which is the standard American telephone number). Also it forces the number to be entered in a E.164 format required by Twilio.

Now, when I go to check the Database Table 'sys_form_inputs' > sys_account > Phone. I see this:

checker_func: preg
checker_params: a:1:{s:4:"preg";s:24:"^\+[1]\d{10}$";}

As you can tell, the UNA system stored my regex in the database differently and added more stuff to it in the checker_params: a:1:{s:4:"preg";s:24:"^\+[1]\d{10}$";}.

Maybe that is what is causing this bug with the Phone Input when I enable the Regular Expression in Studio. (just guessing)

BUG 2:

The 'Custom Check....' value of the option 'Check for...' disappears completly from the select list (dropdown list).

In the Phone Field setting, Studio > Form > Fields > System > Create Account and Edit Account > Phone, there is this option:

Check for:

  • Data Availabily...
  • Data Lengh..
  • Regular Expression...
  • Email...
  • Custom Check...

The default value of this option is: 'Custom Check' which allows to check the already existing number.

If you select something else, let's say: 'Regular Expression...' and enter the Regex, then save, when you would like to go back (reverse) to 'Custom Check...' again (like in my case), then 'Custom Check...' disappears completely from the select list (the dropdown list).

I discovered it after finding out that the Regular Expression in the Phone Input field was not working at all. I wanted to reverse to the default setting but 'Custom Check...' was no longer there. Consequence: I was able to create an account with an already existing number on my Dev Site. No more already existing number check.

The only way for me to fix it and restore things was manually through the Database (phpMySQL). I had go to the 'sys_form_inputs' table > sys_account > Phone, then add the following value in the in the 'checker_func' field:

phoneexist

Then 'Custom Check' appeared back as the default selection in Studio and already existing number check started working back on the Account Creation page. 

IMPORTANT:

I have been told by @LeonidS that the Phone Input field uses the method function checkPhoneExist($s)

which uses the following regular expression:

if(!preg_match("/^\+[0-9\s]*$/", $s)) {

This method checks if the phone is already used by another member.

And if I use my the custom Regex check for the phone number then I will lose the use of the checkPhoneExist method built in UNA.

So, I got no choice but to use my Regular Expression over the checkPhoneExist method. Sure, I will lose the already existing Phone check but at least I will manage to restrict the account creation to a specific region using the Phone input field. (It's exactly what I would like to achieve)

The Dev team should have built things to allow the use of a custom Regex without overwriting the  checkPhoneExist method/function built in the script. I still wonder why they didn't think about it?

WORKAROUND:

If the Regular Expression option of the Phone input field in UNA were working, that would have been easier and a perfect workaround to the lost of the ability to check the already existing Phones.

I would have just set the option: 'Check for: Regular Expression...', and use my Regex:

^\+[1]\d{10}$

Then enable this option of the Phone Field:

'Unique - Check if the field should have unique value.'

This option ('Unique') checks the already existing number. The only difference between enabling 'Unique' and using the 'function checkPhoneExist($s)' is that one gives you this message: 

The field should have unique value

and the other gives you this one:

This phone number is already used by someone

But both methods works almost the same because they check if the value is unique (if the number already exists).

After setting up the Phone Field as explained above, I would have edited the message 'The field should have unique value' through Polygot to reflect the error. Example: 'The field should have unique value or This phone number is already used by someone'.

Please correct me if I am wrong with this workaround.

CONCLUSION:

There are bugs in the Phone input field and the Regular Expression option doesn't work at all. How to fix them?

Using the Regex is crucial to me as I would like to restrict the account creation to a specific region by restricting the Phone number a user can enter. I am setting up a country-specific community (localized website).

Many Thanks

  • 599
Comments
    • BUG 1:

      The correct regular expression in your case would be:

      ~^\+[1]\d{10}$~ 
      

      or

      #^\+[1]\d{10}$# 
      

      You can see the example in the field description:

        • Hi @Alex T⚜️

          You made my day today. Thank you soooo much. My Regex works now. 

          I am sorry, Bug 1 was not a bug. It was just my lack of knowledge. :)

          Also, thanks for opening a ticket on GitHub to fix the Bug 2.

          Honestly, I didn't know that we should open and close the regex with the # or ~ sign in UNA. The field description text is small and gray, I didn't pay attention to it.

          The regex works fine now but the only problem is that I have lost the ablity to check already existing phone numbers which is availabe in the method function checkPhoneExist($s) when you select: 'Custom Check...' (phoneexist) . I have mentioned about it in my post above.

          As a workaround, I am using the regular expression in conjunction with the option: 'Unique - Check if the field should have unique value.'

          It works great because it checks if the field is unique (if the phone already exist). The only difference is that it gives this error message:

          The field should have unique value

          instead of:

          This phone number is already used by someone.

          That's why I will have to edit this text in Polyglot to have something that will be clear to users.

          My question is: Can you make it possible to use any other Check method (e.g. Regex) without losing the default method: 'Custom Check' (the already existing phone check.)? Meaning using both at the same time.

          Many Thanks

          • Can you make it possible to use any other Check method (e.g. Regex) without losing the default method: 'Custom Check' (the already existing phone check.)? Meaning using both at the same time.

            Sorry it's possible to have only one checker function

            • Ok Alex. I understand. Thank you. What about hacking the code? Is there a way to hack the Custom Check (the checkPhoneExist($s) function) to include my regex? I don't want to lose the already existing phone check while being able to make sure that only U.S. mobile number are entered in the phone field.

              Login or Join to comment.