Form validation before save

I know it’s popular question, but I can’t find complex solution.
I have custom field in Account module (let say ‘field1’).
Needs to validate this field on Edit View before save.
My requirements are:

  • no empty (custom message: “Field can’t be empty”)
  • 10 digits format (custom message: “Wrong format”)
  • must be unique (custom message: “Already in database”)

Have you tried something like this?

I found solution. It’s working :slight_smile:

Very cool post, that one. Thanks for sharing. :slight_smile:

step 1 . include custom js file in editviewdefs/detailviewdefs (custom/module/module_name/metadata)

     'includes' => 
          array (
            0 => 
            array (
              'file' => 'custom/include/javascript/peopleAndCompany.js',
          'useTabs' => false,

step2. call internally called function before save or return false until condition not true

    function check_form(form_name){

            cstm_validate = validate_form(form_name,'');

           if (cstm_validate  && other_condition)
              return true;
          return false;


Btw do you have any idea how to implement this one with multiple criteria. For example you`ll check firts_name, last name and mobile number if exist.