Announcement

Collapse
No announcement yet.

Validate via Regex or Formula - EIN / TIN / SSN fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validate via Regex or Formula - EIN / TIN / SSN fields

    Is it possible to Validate a varchar or int field for specific values such as EIN/TIN/SSN (Employee ID Number/Tax ID Number/Social Security Number) before the record is saved to the DB?
    such as Regex: /^(?:\d{3}-\d{2}-\d{4}|\d{2}-\d{7})$/ or even a Formula for this?

    Resources: http://regexlib.com/Search.aspx?k=ssn & http://regexlib.com/REDetails.aspx?r...ookieSupport=1

  • #2
    With UI - no. Only if you develop it. With before save hook or with view overwritten.

    Comment


    • #3
      How can I overwrite the view and tell it to validate in the overwritten view?

      Comment


      • #4
        As usual override the view of the field in entityDefs


        inherit varchar field view,
        define own validate function
        EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.


        check how was email field validation implemented

        Comment


        • khopper
          khopper commented
          Editing a comment
          I do not see where "var msg" is pulling from.
          Last edited by khopper; 04-20-2018, 03:18 AM.

      • #5
        EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.

        as you can see, the 3rd parameter is empty, so it's get form Global

        Comment


        • khopper
          khopper commented
          Editing a comment
          If I modify "Global.json" file with custom message for new function will it save after upgrade or is there a custom path for this?

      • #6
        create it in the custom folder

        custom/Espo/Custom/Resources/i18n/en_US/Global.json
        {
        "messages":{
        "{your label}": "message text"
        }
        }

        Comment


        • #7
          I created 1 file for this and modified the other since it already existed.
          However when I rebuild the backend the Opportunity Page starts showing bad server response.
          Any help would be appreciated.

          client/custom/src/views/opportunity/fields/taxid.js (copied and modified from the email validation js file) Attached.
          &
          custom/Espo/Custom/Resources/metadata/entityDefs/Opportunity.json

          "taxid": {
          "type": "varchar",
          "view": "custom:views/opportunity/fields/taxid",
          "required": false,
          "trim": true,
          "audited": false,
          "readOnly": false,
          "tooltip": true,
          "isCustom": true,
          "tooltipText": "Tax ID is required for WinBack SSN: 000-00-0000 or TIN/EIN 00-0000000"
          },
          Attached Files

          Comment


          • #8
            Hi,
            if you have Bad server response, always check logs (espo and server error). Maybe your file is not valid or any other error.

            About js - didn't run, but your validation function has to be named with camel case style: validateTaxidData
            and view name has to be the same as in entityDefs file - custom:views/opportunity/fields/taxid
            and you set own templates.... did you create these files in client/res/templates/fields ? do you really need them? and why not in custom?
            Last edited by tanya; 04-25-2018, 02:37 PM.

            Comment


            • #9
              Your right I did not need the templates = removed those from the js
              The Bad server response was due to my custom global.json file = resolved.
              Now nothing loads when trying to create or view an Opportunity.
              Nothing shows in the Espo logs saying there is a problem. LogLevel = DEBUG
              Attached Files

              Comment


              • #10
                and view name has to be the same as in entityDefs file - custom:views/opportunity/fields/taxid

                now problem could be only with js, so for this you need to open browser log

                Comment


                • #11
                  This is what i get looking at the Debugger - it shows syntax error but it doesn't say where.
                  Chrome seems to give more detail than Firefix.
                  Last edited by khopper; 04-25-2018, 08:18 PM.

                  Comment


                  • #12
                    attach the file again

                    Comment


                    • #13
                      By the Way I resolved the syntax error but now nothing loads/displays when clicking on View or Create Opportunity with the JS file.
                      I can't find the errors.
                      Attached Files
                      Last edited by khopper; 04-26-2018, 02:11 PM.

                      Comment


                      • #14
                        Originally posted by tanya View Post
                        and view name has to be the same as in entityDefs file - custom:views/opportunity/fields/taxid
                        !!!!!!!!!

                        the path to the file has to be correspond to view name, and view name in entityDefs has to be the same as in view file

                        and I think you don't need to declare methods data and validateRequired

                        Comment


                        • #15
                          My apologizes I missed that detail. I made the changes as suggested.
                          Everything loads up however the validation does nothing. I can enter anything I want without getting a message preventing me from saving.
                          I have attached the new JS file and a screen shot of the saved result in the field.
                          Attached Files

                          Comment

                          Working...
                          X