I am creating an app for use in Australia, over here the mobile number is 10 digits long. When creating a User I want to ensure that the mobile number length is exactly 10 digits, no more no less. I can limit the maximum length of the field by entering 10 in the Field length from the doctype settings. To validate the minimum length I wrote the following script but it does not seem to work. Any help is appreciated
Script:
frappe.ui.form.on(“User”, “validate”, function(frm) {
if (frm.doc.mobile_no.length < ‘10’){
frappe.msgprint(__(“Enter a valid Mobile Number”));
frappe.validated = false;
}
});
Nevermind, got it to work by removing the comas from 10. However another issue has risen now, Alongside Mobile Number I wish to pass the same validation for Phone Number. If i write another If condition in this script, it doesn’t work. Any ideas as to how to pass two validate functions in one script?
It should work with 2 if statements. Can you provide your code?
And checking for
<>10
instead of
<10
may be more appropriate along with the numeric char control.
Ill try using OR and AND instead of the characters, however There is another field I wish to validate. Is there not any way I could pass Multiple IF conditions rather than multiple conditions in one IF condition? Like the code I wrote with two IF’s?
SyntaxError: Unexpected identifier
at init.setup (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1128580)
at frappe.ui.form.Form.setup (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1178920)
at frappe.ui.form.Form.refresh (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1182070)
at frappe.views.FormFactory.render (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1086895)
at http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1086606
at Object.callback (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:160924)
at Object.success [as success_callback] (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:61576)
at 200 (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:61881)
at Object. (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:64479)
at i (http://vertex360.com.au/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)
This is my code:
frappe.ui.form.on(“User”, “validate”,function(frm) {
if (frm.doc.phone_number.length != 10 AND frm.doc.mobile_number.length != 10){
frappe.msgprint(__(“Enter a valid phone Number”));
frappe.validated = false;
}
});
SyntaxError: Invalid or unexpected token
at init.setup (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1128580)
at frappe.ui.form.Form.setup (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1178920)
at frappe.ui.form.Form.refresh (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1182070)
at frappe.views.FormFactory.render (http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1086895)
at http://vertex360.com.au/assets/js/form.min.js?ver=1612317133.0:1:1086606
at Object.callback (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:160924)
at Object.success [as success_callback] (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:61576)
at 200 (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:61881)
at Object. (http://vertex360.com.au/assets/js/desk.min.js?ver=1612317133.0:1:64479)
at i (http://vertex360.com.au/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)
Maybe it is the " that is got smart-converted to prettified?
Can you repost the code and put it inside ``` so easier to see?
I copy and paste your above code here:
Try this code.
frappe.ui.form.on (“Usuario”, “validar”, función (frm) {
if (frm.doc.phone_number.length<10) {
msgprint=("Enter a valid phone Number ”);
validate= false;
}
if (frm.doc.mobile_number.length<10) {
msgprint=("Enter a valid mobile Number ”);
validate= false;
}
)};