nepali_input_formatters 0.0.1
nepali_input_formatters: ^0.0.1 copied to clipboard
A collection of Flutter TextInputFormatters, validators, and utilities tailored for Nepali data formats (phone numbers, citizenship, and Lakhs/Crores currency).
Flutter TextInputFormatters and FormFieldValidators for Nepali data:
mobile numbers, citizenship numbers, and Lakh/Crore-grouped currency
amounts. Drop them straight into a TextFormField — no manual regex or
masking code required.
Features #
| Data | Formatter | Validator |
|---|---|---|
| Mobile number | NepaliPhoneDigitsFormatter, NepaliPhoneNumberFormatter |
validateNepaliPhoneNumber |
| Citizenship number | CitizenshipDigitsFormatter, CitizenshipNumberFormatter |
validateCitizenshipNumber |
| Currency amount | SouthAsianCurrencyFormatter |
validateCurrencyAmount |
- Live formatting — groups digits as the user types (
984-123-4567,12-01-70-12345,12,34,567), including correct cursor placement and backspace-over-separator handling. - Telecom detection —
identifyNepaliTelecomtells you whether a mobile number belongs to NTC or Ncell, based on its prefix. - Formatting-aware validators — every validator strips separators before checking the value, so it works whether the field used a formatter or not.
- No dependencies beyond Flutter itself.
Getting started #
Add the package to your pubspec.yaml:
dependencies:
nepali_input_formatters: ^0.0.1
Then import it:
import 'package:nepali_input_formatters/nepali_input_formatters.dart';
Usage #
Mobile number #
TextFormField(
keyboardType: TextInputType.phone,
inputFormatters: const [NepaliPhoneNumberFormatter()],
validator: validateNepaliPhoneNumber,
decoration: const InputDecoration(
labelText: 'Mobile number',
hintText: '984-123-4567',
),
)
NepaliPhoneNumberFormatter groups digits as 3-3-4 (e.g.
984-123-4567) and caps input at 10 digits. If you'd rather keep the
raw digits in the field and format only for display, use
NepaliPhoneDigitsFormatter instead — it restricts input to digits
without inserting separators.
Both formatters accept a custom separator:
const NepaliPhoneNumberFormatter(separator: ' ')
To detect the operator (NTC or Ncell) as the user types:
onChanged: (value) {
final digits = value.replaceAll(RegExp(r'[^0-9]'), '');
final telecom = identifyNepaliTelecom(digits); // NepaliTelecom.ntc / .ncell / .unknown
}
Citizenship number #
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: const [CitizenshipNumberFormatter()],
validator: validateCitizenshipNumber,
decoration: const InputDecoration(
labelText: 'Citizenship number',
hintText: '12-01-70-12345',
),
)
CitizenshipNumberFormatter groups the 11 digits as 2-2-2-5
(district code, registration office code, registration year, serial
number). Use CitizenshipDigitsFormatter if you only want the digits
restricted to 11 characters, without grouping.
Currency amount (Lakh/Crore grouping) #
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: const [SouthAsianCurrencyFormatter()],
validator: validateCurrencyAmount,
decoration: const InputDecoration(
labelText: 'Amount (NPR)',
hintText: '12,34,567',
),
)
SouthAsianCurrencyFormatter groups whole-number input using the South
Asian numbering system: the last 3 digits form one group, and every
group to its left is 2 digits (e.g. 1234567 → 12,34,567). It's
digit-only — no decimal point or currency symbol — so add a prefix
(Rs. ) via InputDecoration.prefixText if you need one.
Validators without formatters #
Every validator matches Flutter's FormFieldValidator<String>
signature and strips separators internally, so they also work on plain,
unformatted text fields:
TextFormField(
validator: validateCurrencyAmount, // works even without SouthAsianCurrencyFormatter
)
Example #
A full runnable demo combining all three fields, live operator
detection, and form validation is in example/.
Additional information #
- Scope — NTC and Ncell mobile prefixes only. Smart Cell/Smart Telecom is intentionally excluded since NTA permanently closed the operator.
- Issues & feature requests — file them on the issue tracker.
- Contributing — PRs are welcome. Please include tests for any new formatter or validator.
- License — MIT.