User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:adminmanual:businessmappings:validations [2019/01/02 00:17]
joebordes [Expression Map]
en:adminmanual:businessmappings:validations [2019/03/19 09:23] (current)
timothy
Line 17: Line 17:
           <​restriction>​{values depend on the rule}</​restriction>​           <​restriction>​{values depend on the rule}</​restriction>​
           </​restrictions>​           </​restrictions>​
 +          <​message>​This is my custom msg for field: {field}</​message> ​ {optional}
         </​validation>​         </​validation>​
         .....         .....
Line 42: Line 43:
   *array - Must be array   *array - Must be array
     *restrictions:​ none     *restrictions:​ none
-  *length - String must be certain length+  *length - String must be certain length
     *restrictions:​ number     *restrictions:​ number
   *lengthBetween - String must be between given lengths   *lengthBetween - String must be between given lengths
-    *restrictions:​ two restriction ​of type number+    *restrictions:​ two restrictions ​of type number
   *lengthMin - String must be greater than given length   *lengthMin - String must be greater than given length
     *restrictions:​ number     *restrictions:​ number
Line 72: Line 73:
   *slug - URL slug characters (a-z, 0-9, -, _)   *slug - URL slug characters (a-z, 0-9, -, _)
     *restrictions:​ none     *restrictions:​ none
-  *regex - Field matches given regex pattern+  *regex - Field matches ​given regex pattern
     *restrictions:​ regular expression. be careful you may have to put this inside a CDATA     *restrictions:​ regular expression. be careful you may have to put this inside a CDATA
   *date - Field is a valid date   *date - Field is a valid date
Line 87: Line 88:
     *restrictions:​ list of accepted credit cards, if none given all supported cards will be checked     *restrictions:​ list of accepted credit cards, if none given all supported cards will be checked
     *supported cards: Visa visa, Mastercard mastercard, Dinersclub dinersclub, American Express amex or Discover discover     *supported cards: Visa visa, Mastercard mastercard, Dinersclub dinersclub, American Express amex or Discover discover
 +  *requiredWith -  Field is required if any other fields are present
 +    *restrictions:​ list of fields
 +  *requiredWithout - Field is required if any other fields are NOT present
 +    *restrictions:​ list of fields
   *IBAN_BankAccount - validate IBAN Bank Account number   *IBAN_BankAccount - validate IBAN Bank Account number
     *restrictions:​ none     *restrictions:​ none
Line 97: Line 102:
   *custom - launch custom function that can be found in the indicated file   *custom - launch custom function that can be found in the indicated file
     * restrictions:​ file name, validation test name, function name and label to show on error (will be translated)     * restrictions:​ file name, validation test name, function name and label to show on error (will be translated)
 +
 +<WRAP center round info 100%>
 +All of the rules above accept an optional directive named __message__ where you can set the error message you want the user to see when an error on that field happens. If this is not established a standard error message will be returned. Inside this message you can use the curly brace __field__ tag to indicate where you want the field name to appear:
 +  <​message>​This is my custom msg for field: {field}</​message>​
 +</​WRAP>​
  
 <WRAP center round info 100%> <WRAP center round info 100%>
Line 208: Line 218:
 </​map></​code>​ </​map></​code>​
  
 +
 +This next example contains a REGEX expression that will not accept any alphabetical letter in the accountname field and there must be at least one character. Important things to notice in the REGEX expression are:
 +
 +  - you must set the initial and end of line markers as the value is compared as a complete string
 +  - you may or may not need the CDATA depending on the regex (the one below does not need CDATA)
 +  - modifiers are not supported in the expression
 +
 +
 +<code XML>
 +<map>
 +  <​originmodule>​
 +    <​originname>​Accounts</​originname>​
 +  </​originmodule>​
 +  <​fields>​
 +    <​field>​
 +      <​fieldname>​accountname</​fieldname>​
 +      <​validations>​
 +        <​validation>​
 +          <​rule>​regex</​rule>​
 +          <​restrictions>​
 +          <​restriction><​![CDATA[/​^[^A-Za-z]+$/​]]></​restriction>​
 +          </​restrictions>​
 +        </​validation>​
 +      </​validations>​
 +    </​field>​
 +  </​fields>​
 +</​map>​
 +</​code>​
 ==== Forum Post with a very advanced example of a custom validation ==== ==== Forum Post with a very advanced example of a custom validation ====
  
Line 231: Line 269:
     * isValidPersonalESID = isValidDNI or isValidNIE or isValidNIF     * isValidPersonalESID = isValidDNI or isValidNIE or isValidNIF
     * isValidESID = isValidPersonalESID or isValidCIF     * isValidESID = isValidPersonalESID or isValidCIF
 +  * Italian ID Number: file include/​validation/​validatePIVA.php
 +    * checkAccountPIVA
  
 For example, a validation for a valid CIF on account siccode field looks like this: For example, a validation for a valid CIF on account siccode field looks like this:
Line 354: Line 394:
 <map> <map>
   <​expression>​if employees > 10 then 1 else 0 end</​expression>​   <​expression>​if employees > 10 then 1 else 0 end</​expression>​
 +</​map>​
 +</​code>​
 +
 +====Custom Message Test Map====
 +
 +<code XML>
 +<map>
 +  <​originmodule>​
 +    <​originname>​Accounts</​originname>​
 +  </​originmodule>​
 +  <​fields>​
 +    <​field>​
 +      <​fieldname>​industry</​fieldname>​
 +      <​validations>​
 +        <​validation>​
 +          <​rule>​notIn</​rule>​
 +          <​restrictions>​
 +          <​restriction>​Banking</​restriction>​
 +          </​restrictions>​
 +          <​message>​This is my custom msg for field: {field}</​message>​
 +        </​validation>​
 +        <​validation>​
 +          <​rule>​notIn</​rule>​
 +          <​restrictions>​
 +          <​restriction>​Energy</​restriction>​
 +          </​restrictions>​
 +          <​message>​Energy not supportted for: {field}</​message>​
 +        </​validation>​
 +        <​validation>​
 +          <​rule>​notIn</​rule>​
 +          <​restrictions>​
 +          <​restriction>​Apparel</​restriction>​
 +          </​restrictions>​
 +        </​validation>​
 +      </​validations>​
 +    </​field>​
 +  </​fields>​
 </​map>​ </​map>​
 </​code>​ </​code>​