function validatePhoneNumber(str) { var phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; if (!str || !str.match(phoneno)) { return false; } return true; } const thaiMonths = [ "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค." ]; function thaiDateShort(inputDate) { const formattedDate = moment(inputDate).format('D'); const thaiMonthIndex = moment(inputDate).month(); const thaiYear = parseInt(moment(inputDate).format('YYYY')) + 543; return formattedDate + " " + thaiMonths[thaiMonthIndex] + " " + thaiYear.toString().slice(-2); } function dateShort(inputDate) { return moment(inputDate).format('DD-MM-YYYY') } function formatTimestamp(timestamp) { var months = ["", "ม.ค", "ก.พ", "มี.ค", "เม.ย", "พ.ค", "มิ.ย", "ก.ค", "ส.ค", "ก.ย", "ต.ค", "พ.ย", "ธ.ค"]; var date = new Date(timestamp * 1000); // Convert timestamp to milliseconds var day = date.getDate(); var month = months[date.getMonth() + 1]; var time = date.toLocaleTimeString('en-GB', { hour12: false, hour: '2-digit', minute: '2-digit' }); return day + " " + month + " " + time; } function validateEmail(email) { const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return regex.test(email); } // Thai translations const timeagoTh = (number, index, totalSec) => { // console.log(number, index, totalSec); return [ ['เมื่อกี้', 'สักครู่'], ['เมื่อกี้', 'สักครู่'], ['เมื่อกี้', 'สักครู่'], ['%s นาทีที่แล้ว', 'ใน %s นาที'], ['1 ชั่วโมงที่แล้ว', 'ใน 1 ชั่วโมง'], ['%s ชั่วโมงที่แล้ว', 'ใน %s ชั่วโมง'], ['1 วันที่แล้ว', 'ใน 1 วัน'], ['%s วันที่แล้ว', 'ใน %s วัน'], ['1 อาทิตย์ที่แล้ว', 'ใน 1 อาทิตย์'], ['%s อาทิตย์ที่แล้ว', 'ใน %s อาทิตย์'], ['1 เดือนที่แล้ว', 'ใน 1 เดือน'], ['%s เดือนที่แล้ว', 'ใน %s เดือน'], ['1 ปีที่แล้ว', 'ใน 1 ปี'], ['%s ปีที่แล้ว', 'ใน %s ปี'], ][index]; }; timeago.register('th', timeagoTh); const thaiTimeago = timeago(null, 'th'); const elements = document.querySelectorAll('.timeago'); thaiTimeago.render(elements);