UNPKG

snapotp-jquery

Version:

SnapOTP is a lightweight and customizable jQuery plugin to create elegant multi-input OTP fields with features like auto-focus, paste handling, keyboard navigation, and callbacks.

137 lines (90 loc) โ€ข 2.87 kB
# SnapOTP jQuery Plugin SnapOTP is a lightweight and customizable jQuery plugin to create elegant multi-field OTP (One-Time Password) input interfaces. It supports features like auto-focus, keyboard navigation, smart paste handling, reset control, and event callbacks โ€” making it perfect for authentication and verification workflows. ![SnapOTP Screenshot](./snapotp-jquery.png) <!-- Optional: Replace or remove if not available --> --- ## ๐Ÿš€ Features - ๐Ÿ”ข Configurable OTP digit length - ๐ŸŽฏ Auto-focus to next field - ๐Ÿ”„ Smart paste support (entire OTP from clipboard) - ๐ŸŽน Keyboard navigation with Arrow keys & Backspace - ๐Ÿ” Reset method (`resetSnapOTP`) - ๐Ÿ”” Events: `onComplete`, `onChange`, `onEnter` - ๐Ÿง‘โ€๐ŸŽจ Input styling via `data-style` attribute (`box`, `underline`, `circle`) --- ## ๐Ÿ“ฆ Installation ### 1. Include jQuery ```html <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> ``` ### 2. Include SnapOTP JS and CSS ```html <link rel="stylesheet" href="snapotp.css"> <script src="snapotp.js"></script> ``` --- ## ๐Ÿง‘โ€๐Ÿ’ป Usage ### HTML ```html <div id="otp"></div> ``` ### JavaScript ```javascript $('#otp').snapOTP({ digits: 6, onComplete: function (code) { console.log('OTP Entered:', code); }, onChange: function (code) { console.log('OTP Changed:', code); }, onEnter: function (code) { alert('Enter pressed: ' + code); }, type: 'number', // or 'text' style: 'box' // box | underline | circle }); ``` --- ## ๐Ÿงช Methods ### Reset OTP inputs ```javascript $('#otp').resetSnapOTP(); ``` This will clear all fields and focus on the first input. ### Get Value ```javascript $('#otp').getValue(); ``` This will get value of input and return it. --- ## ๐ŸŽจ Styling SnapOTP supports basic styling using the `data-style` attribute on the container: ```html <div id="otp" data-style="underline"></div> ``` Available styles: - `box` (default) - `underline` - `circle` Customize styles in your CSS based on the `[data-style]` attribute. --- ## ๐Ÿ“ File Structure ``` ๐Ÿ“ฆ /dist/snapotp-jquery โ”œโ”€โ”€ ๐Ÿ“„ snapotp.js โ€“ Core plugin logic (jQuery-based) โ””โ”€โ”€ ๐ŸŽจ snapotp.css โ€“ Default styling (easily customizable) ``` --- ## ๐Ÿ‘จโ€๐ŸŽจ Author **Nitin Rathod** ๐Ÿ”— GitHub: [@nitinramrathod](https://github.com/nitinramrathod) ๐Ÿ“ง Email: rathod173ram@gmail.com ๐Ÿ“ฑ Mobile: +91-8459556244 ๐Ÿ“ Location: Thane, Maharashtra, India --- ## ๐Ÿ“„ License Licensed under the MIT License. Feel free to use, modify, and distribute with attribution. --- ## ๐ŸŒ Repository **GitHub:** [https://github.com/nitinramrathod/snapotp-jquery](https://github.com/nitinramrathod/snapotp-jquery)