Mobile Number Length Validation in ErpNext

Use this code in Java script file
frappe.ui.form.on(‘Customer Login’, {
mobile_no: function(frm) {
if (frm.doc.mobile_no){
frappe.call({
method: “validate_mob_number”,
doc:frm.doc,
callback: function(r) {
}
});
}
}
});

“Next step is to add the codes return below in your Python file”

@frappe.whitelist()
def validate_mob_number(self):
if len(self.mobile_no) < 10:
frappe.msgprint(“Mobile number is invalid”)

frappe.ui.form.on(‘Customer_Login’, ‘validate’, function(frm) {
if (frm.doc.mobile_no.length<10) {
msgprint(‘The Mobile Number is invalid’);
Validate = false;
}
});

Try it

Check this:

https://frappeframework.com/docs/v14/user/en/api/utils#validate_phone_number

frappe.ui.form.on(‘User’, ‘validate’,function(frm) {
if (frm.doc.phone_number.length < 10){
frappe.msgprint((“Enter a valid phone Number”));
frappe.validated = false;
}
});