Hi, everyone.
I added a custom field in my Employee doctype called “Aadhaar Number” with a word limit set to 12.
Now, I want the field to accept only numerical values and to save only if the number is exactly 12 digits long. If the number is less than 12 digits, it should not allow saving. How can I achieve this?
frappe.ui.form.on('Employee', {
validate: function(frm) {
let aadhaarNumber = frm.doc.
// Check if Aadhaar Number is exactly 12 digits long
if (!/^\d{12}$/.test(aadhaarNumber)) {
frappe.msgprint(__('Aadhaar Number must be exactly 12 digits long.'));
frappe.validated = false;
}
}
});
frappe.ui.form.on('Your Doctype', {
validate: function (frm) {
var aadhar_number = frm.doc.aadhar_number;
var esic_number = frm.doc.esic_number;
var uan_number = frm.doc.uan_number;
if (aadhar_number && aadhar_number.length !== 12) {
frappe.msgprint(__('Aadhar card number must be 12 digits.'));
frappe.validated = false;
}
if (esic_number && esic_number.length !== 17) {
frappe.msgprint(__('ESIC number must be 17 digits.'));
frappe.validated = false;
}
if (uan_number && uan_number.length !== 12) {
frappe.msgprint(__('UAN number must be 12 digits.'));
frappe.validated = false;
}
}
});
Please set your doctype name and field name in script.