<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Yallison Reis</title>
    <description>The latest articles on Forem by Yallison Reis (@ygreis).</description>
    <link>https://forem.com/ygreis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3813407%2Fd22075fe-3c66-4a23-8f9e-7526199304c7.jpeg</url>
      <title>Forem: Yallison Reis</title>
      <link>https://forem.com/ygreis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ygreis"/>
    <language>en</language>
    <item>
      <title>A headless library for international phone inputs</title>
      <dc:creator>Yallison Reis</dc:creator>
      <pubDate>Sun, 08 Mar 2026 20:06:18 +0000</pubDate>
      <link>https://forem.com/ygreis/a-headless-library-for-international-phone-inputs-43el</link>
      <guid>https://forem.com/ygreis/a-headless-library-for-international-phone-inputs-43el</guid>
      <description>&lt;p&gt;International phone inputs are surprisingly tricky to implement&lt;br&gt;
correctly.&lt;/p&gt;

&lt;p&gt;Formatting, validation, country detection, and handling edge cases can&lt;br&gt;
quickly become complex when building phone input fields for different&lt;br&gt;
regions.&lt;/p&gt;

&lt;p&gt;Over the weekend, I built a small open-source library to experiment with&lt;br&gt;
a different approach: a headless engine that handles parsing, masking,&lt;br&gt;
and validation of international phone numbers while leaving the UI&lt;br&gt;
completely up to the developer.&lt;/p&gt;

&lt;p&gt;The core is powered by libphonenumber-js and exposes a deterministic&lt;br&gt;
state object that can be used with any framework.&lt;/p&gt;

&lt;p&gt;Main ideas behind the project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Headless architecture (no UI components)&lt;/li&gt;
&lt;li&gt;  Smart masking based on libphonenumber&lt;/li&gt;
&lt;li&gt;  Country auto-detection while typing&lt;/li&gt;
&lt;li&gt;  Deterministic state output&lt;/li&gt;
&lt;li&gt;  Works with React, React Native, Vue, Angular or vanilla JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IntlPhoneCore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;applyClampedValue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@intl-phone-js/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IntlPhoneCore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;applyClampedValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Links:&lt;/p&gt;

&lt;p&gt;Documentation: &lt;a href="https://ygreis.github.io/dev-hub/lib/intl-phone-js-core" rel="noopener noreferrer"&gt;https://ygreis.github.io/dev-hub/lib/intl-phone-js-core&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub Repository: &lt;a href="https://github.com/ygreis/intl-phone-js" rel="noopener noreferrer"&gt;https://github.com/ygreis/intl-phone-js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NPM: &lt;a href="https://www.npmjs.com/package/@intl-phone-js/core" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/@intl-phone-js/core&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’d love to hear feedback from anyone who has worked with phone input&lt;br&gt;
libraries before.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
