Twilio Examples

SMS Phone Verification

This is a basic SMS phone verification example. How it works:

  • It uses Twilio Verify to verify phone numbers and add an additional layer of security
    • Helps prevent fraudulent users from registering with your business
  • It renders a UI to create an account on a (fictional) website
    • The customer would enter a username, password and phone number
  • It will then send the customer an SMS for 2-Factor Authentication (2FA)
  • The customer will be asked to enter a verification code into the webpage to verify their account
  • When the app receives the SMS from the customer, it will validate the verification code entered against the Twilio Verify service

const result = await account.verify.v2 .services(VERIFICATION_SERVICE_SID) .verifications.create({ to: phoneNumber, channel });


Get code


const verificationCheck = await account.verify.v2 .services(VERIFICATION_SERVICE_SID) .verificationChecks.create({ to: phoneNumber, code: verificationCode });


Verify code