Most of our products sign people in with a phone number and a 6-digit code, usually sent by WhatsApp. Typing that code is the moment people give up: they switch apps, memorise six digits, switch back, mistype one. In October 2026 we set a rule for every product: a code screen that does not fill itself is not finished. This is the single script that does it on the web, the small native piece that does it in our Android apps, and the parts that still do not work.
TL;DR
- iPhone:
autocomplete="one-time-code"plusinputmode="numeric"makes Safari offer the code from Messages above the keyboard. One attribute, no JavaScript. - Android Chrome: the WebOTP API reads the code from an SMS whose last line is
@your-domain #123456. - WhatsApp: authentication templates carry a "copy code" button. When the user comes back to the page, we read the clipboard if the browser allows it, and a paste handler catches the rest.
- Our Android apps: WhatsApp one-tap / zero-tap and Android's SMS User Consent hand the code to the native shell, which passes it into the web page.
- One script handles all of it, finds code fields by itself, converts Arabic digits, spreads a pasted code over split boxes and submits when the code is complete.
The problem
Each platform has its own way of reading a code, and each one has conditions that are easy to miss:
| Where the user is | Code arrives by | What can fill it |
|---|---|---|
| iPhone, Safari or an in-app browser | SMS | one-time-code suggestion from Messages |
| iPhone | Nothing automatic. Copy button, then paste | |
| Android Chrome | SMS | WebOTP, only with the @domain #code line |
| Android or desktop Chrome | Clipboard read when the user returns | |
| Our Android app | One-tap / zero-tap, after a handshake | |
| Our Android app | SMS | SMS User Consent sheet |
On top of that, our users are in Egypt and the Gulf, where many keyboards type Arabic-Indic digits (٠١٢٣). A field that expects [0-9]{6} rejects a perfectly correct code typed on an Arabic keyboard.
Why the per-page approach failed
Before the rule, each product had some of this. One sign-up form had one-time-code; another had a hand-written paste handler; a partner sign-in had neither. Every new code screen (forgot password, phone change, a second login step) was a fresh chance to forget. Copying good code from page to page does not scale, because the next page is always written in a hurry.
So we went the other way: one script, included once in every layout, that finds code fields by itself. A page only has to mark its field, and the markup it needs is the markup it should have anyway.
The fix: one script, no page code
The field looks like this:
<input id="otp" name="otp" type="text"
autocomplete="one-time-code" inputmode="numeric"
pattern="[0-9]{6}" maxlength="6" required>
The script picks up any input[autocomplete="one-time-code"], plus a class or data attribute for older fields, and adds these behaviours.
1. Typing and pasting
Arabic-Indic and Persian digits become ASCII as they are typed, and anything that is not a digit is dropped. A paste is searched for the code, so pasting a whole WhatsApp message ("Your code is 123 456") still works. If the field is split into one box per digit, the code is spread across the boxes. The same path catches the iOS suggestion, which drops all six digits into the first box at once.
function extract(text, n) {
const t = ascii(text).replace(/(\d)[ -](?=\d)/g, '$1'); // "123 456" → "123456"
const m = new RegExp('(?:^|\\D)(\\d{' + n + '})(?!\\d)').exec(t);
if (m) return m[1]; // an exact run of n digits wins
const d = t.replace(/\D/g, '');
return d.length === n ? d : '';
}
When the code is complete, the form submits itself, at most once every four seconds. A form can opt out with data-otp-autosubmit="off".
2. WebOTP on Android Chrome
While a code field is visible, the script holds an open navigator.credentials.get({ otp: { transport: ['sms'] } }) request with an AbortController. It aborts on submit and on leaving the page, and a MutationObserver restarts it when a hidden code step becomes visible. The browser only answers for an SMS that ends with @<the page's host> #<code>, so that line is part of the message format.
3. The WhatsApp copy-code button
WhatsApp authentication templates show a "Copy code" button. The user taps it and comes back to our tab. On visibilitychange and focus, the script asks the Permissions API about clipboard-read:
- If it is already granted, it reads the clipboard silently and fills the field.
- If the browser would prompt, it asks at most once per page, and only if the user really left the page (more than a moment away). Without that, the prompt pops up on page load, which looks like an attack.
- Safari and Firefox do not let us query that permission, so the script skips it there. The user pastes, and the paste handler from step 1 takes over.
A code that has already been used is remembered, so returning to the tab later does not refill an old code.
4. Native: one-tap inside our Android apps
Our Android apps (DentX, Krown, Kauthar AI and others) are native shells around the web app. Right before a code is sent, the page calls a handshake that the shell forwards to native code. The native side does two things:
- It sends WhatsApp's
OTP_REQUESTEDbroadcast with aPendingIntentthat identifies our app. If the template is set to one-tap or zero-tap and lists our package and signing hash, WhatsApp shows "Autofill" or passes the code straight to the app. We accept the code only if thatPendingIntentwas created by WhatsApp itself. - It starts Android's SMS User Consent, so an SMS code shows Google's own "allow this app to read this message?" sheet. We launch that sheet only if it resolves to Google Play services, never an arbitrary intent.
The code comes back through the Flutter bridge as a native-otp event on window, and the same web script fills and submits. The page does not know or care which path delivered it.
What does not work, and what tripped us
The signing hash has to be the Play one. WhatsApp one-tap matches the app by its package name and an 11-character hash of the signing certificate. With Play App Signing, the certificate on users' phones is Google's, not the upload key we sign with. We measured the hashes from the APKs that Play itself generated. A release APK installed by hand carries a different hash and quietly falls back to the copy-code button. The fallback is fine; spending an afternoon wondering why one-tap "does nothing" on a sideloaded build is not.
One-tap is ready, not live. Changing an approved WhatsApp template's button sends it back to Meta for review, and Meta limits template edits. We built the edit as a script that is a dry run by default. Until it is applied and approved, the template keeps its copy-code button, and everything above still works with it.
WebOTP needs control of the SMS text. Where the SMS is sent by a third-party phone-auth service that writes its own message, we cannot add the @domain #code line, and WebOTP stays silent. On those paths the iOS suggestion and paste still work. On our own WhatsApp path it does not apply at all.
Result
- The same 157-line script runs in nine of our codebases, including DentX, Krown, Kauthar AI, Curava, Spotra and GT-Govern.
- In DentX, every code form (WhatsApp, SMS and the partner portal's email code) uses
one-time-code, and the script is loaded by every layout that can show one. - A 27-check offline test guards the wiring: every code field has the right attributes, every layout loads the script, extraction handles WhatsApp and SMS texts with Arabic digits and spaces, and templates for a customer's own WhatsApp number never list our apps.
We have not measured a before-and-after drop-off rate on code screens, so we do not quote one.
Checklist
autocomplete="one-time-code",inputmode="numeric"and a digits pattern on every code field.- Convert Arabic-Indic and Persian digits as the user types.
- Accept a pasted message, not only a pasted code, and spread it over split boxes.
- End your SMS with
@your-domain #codeso WebOTP can read it. - Use WhatsApp authentication templates with the copy-code button; read the clipboard on return only when the browser allows it, and ask at most once.
- In native apps, add one-tap / zero-tap and SMS User Consent, and verify the sender of every intent.
- Put it in one shared script in the layout, and add a test that fails when a code field is missing the attributes.
Need this?
Phone sign-in with WhatsApp codes that fill themselves comes built into every GeoTech product, and Kauthar AI can send those codes for your own business from an official WhatsApp number. If your sign-up loses people at the code screen, talk to GeoTech.