A lightweight, zero-dependency jQuery plugin designed to automatically format Cambodian address strings. It intelligently converts Western Arabic numerals (
0-9) into Khmer digits (០-៩) and adds standard Khmer word spacing between administrative divisions (ភូមិ, ឃុំ, ស្រុក, ខេត្ត, etc.).
- 🇰🇭 Khmer Digit Translation: Automatically normalizes Western numerals (
0-9) to official Khmer digits (០-៩). - 📍 Full Administrative Coverage: Supports all 25 Provinces/Autonomous Municipalities, Districts/Khan, Communes/Sangkat, Villages, and major landmark zones across Cambodia.
- ⌨️ Form Input Auto-Formatting: Rebinds input events (
blur,change,keypress) to clean up address entries dynamically. - 📄 Static Text View Support: Effortlessly formats non-input elements (
<div>,<span>,<p>,<td>) rendered from server-side templates (CodeIgniter, Laravel, WordPress). - ⚡ Performance Optimized: Uses sorted Regex boundary matching to prevent nested string collisions.
npm install jquery-khmer-address-formatter<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/jquery-khmer-address-formatter@1.0.2/dist/jquery.khmer-address-formatter.min.js"></script>
<!-- unpkg -->
<script src="https://unpkg.com/jquery-khmer-address-formatter@1.0.2/dist/jquery.khmer-address-formatter.min.js"></script><input type="text" id="address" placeholder="ភូមិ6សង្កាត់4អូរត្រេះព្រះសីហនុ">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="yourpath/to/jquery.khmer-address-formatter.min.js"></script>
<script>
$(document).ready(function() {
$('#address').khmerAddressFormatter({
spacing: 2,
convertNumbers: true
});
});
</script>| Option | Type | Default | Description |
|---|---|---|---|
event |
string |
'blur' |
Event that triggers formatting ('blur', 'change'). |
spacing |
number |
2 |
Number of spaces to insert between divisions. |
convertNumbers |
boolean |
true |
Automatically converts Western digits (0-9) to Khmer digits (០-៩). |
onFormat |
function |
null |
Callback triggered after formatting (function(formattedValue)). |
You can also format address strings directly without binding to an input element:
const result = $.formatKhmerAddress('ភូមិ1ឃុំបិតត្រាំងស្រុកព្រៃនប់', 2, true);
// Output: "ភូមិ ១ ឃុំ បិតត្រាំង ស្រុក ព្រៃនប់"- Chou Chamnan – Creator & Maintainer
- GitHub: https://github.com/SmarterCoding
- npm: https://www.npmjs.com/~chamnan_dev
Made with ❤️ in Cambodia 🇰🇭
MIT License