Repository: wagtail/wagtail

Issue:
Phone link text should prevent spaces
### Issue Summary

Phone links allow arbitrary formatting for the "Phone number"

<img width="482" alt="Screen Shot 2023-06-13 at 10 01 04 AM" src="https://github.com/wagtail/wagtail/assets/704760/31179abd-1eb0-4048-a5e9-b297511c3094">

However, when the phone number is formatted as (000) 000-0000, it appears to not be valid HTML. Running such a value through the [Nu Html Checker](https://validator.w3.org/nu/) would give:

```
Error: Bad value tel:(000) 000-0000 for attribute href on element [a](https://html.spec.whatwg.org/multipage/#the-a-element): Illegal character in scheme data: space is not allowed.

From line 4909, column 390; to line 4909, column 418

vl">Call: <a href="tel:(000) 000-0000">(000)
```

Meaning the space in `(000) 000-000` is not allowed. 

The UI should probably prompt the user to enter the phone number in a universal phone format that does not include spaces.

### Steps to Reproduce

1. Add a phone link to a page in the form (000) 000-0000 for the link href.
2. Enter the page into https://validator.w3.org/
3. See bad value error for href.

### Technical details

-   Python version:  3.8.12
-   Django version: 3.2.19
-   Wagtail version: 4.1.6
-   Browser version: Chrome 114



Discussion:
Thanks for the report @anselmbradford! I think the logical thing to do here would be to strip out spaces at the point that we make the phone number into a URL: https://github.com/wagtail/wagtail/blob/840498fc1b99ee275e117ade581d977eec25fafe/wagtail/admin/views/chooser.py#L744-L745
> Thanks for the report @anselmbradford! I think the logical thing to do here would be to strip out spaces at the point that we make the phone number into a URL:

Maybe strip any parentheses too? Not sure if `(000)0000000` would be valid either.
If I'm reading [the spec for `tel:` URLs](https://www.rfc-editor.org/rfc/rfc3966#section-3) right, parentheses are allowed as a "visual separator", but spaces are explicitly forbidden (section 5.1.1) - so only spaces should be stripped out.
I believe I can make a PR on this
Hii I am very  much confident to solve this issue please assign me this issue
Thanks for your interest @sivangbagri! We do not assign issues outside of the core team - anyone is free to work on any issue. Now that you've expressed an interest, other people may choose to hold off on picking this up, but they are not required to.

We recommend thoroughly reading https://docs.wagtail.org/en/latest/contributing/first_contribution_guide.html before making your first contribution. You may also wish to join [our #new-contributors channel on Slack](https://github.com/wagtail/wagtail/wiki/Slack).

Resolving patch:
diff --git a/wagtail/admin/views/chooser.py b/wagtail/admin/views/chooser.py
--- a/wagtail/admin/views/chooser.py
+++ b/wagtail/admin/views/chooser.py
@@ -739,4 +739,5 @@ class PhoneLinkView(BaseLinkFormView):
     link_url_field_name = "phone_number"
 
     def get_url_from_field_value(self, value):
+        value = re.sub(r"\s", "", value)
         return "tel:" + value


Test patch:
diff --git a/wagtail/admin/tests/test_page_chooser.py b/wagtail/admin/tests/test_page_chooser.py
--- a/wagtail/admin/tests/test_page_chooser.py
+++ b/wagtail/admin/tests/test_page_chooser.py
@@ -992,6 +992,18 @@ def test_notice_changes_to_link_text(self):
         # link text has changed, so tell the caller to use it
         self.assertIs(result["prefer_this_title_as_link_text"], True)
 
+    def test_phone_number_has_spaces(self):
+        response = self.post(
+            {
+                "phone-link-chooser-phone_number": "+1 234 567 890",
+                "phone-link-chooser-link_text": "call",
+            }
+        )
+        result = json.loads(response.content.decode())["result"]
+        self.assertEqual(result["url"], "tel:+1234567890")
+        self.assertEqual(result["title"], "call")
+        self.assertIs(result["prefer_this_title_as_link_text"], True)
+
 
 class TestCanChoosePage(WagtailTestUtils, TestCase):
     fixtures = ["test.json"]