1. The forums have been upgraded to XenForo 1.4. Please post any issues or comments here.
  2. Our hosting provider will be performing some scheduled maintenance and upgrading during the early morning (US time) of Tue 28th July, starting at approx 2am EST, which will require some down time of the server.

validation is empty or is unique value

Discussion in 'Community Support' started by ErnstJan, Jan 24, 2012.

  1. ErnstJan

    ErnstJan Member

    Level: Community
    Hello,

    In a form I have a field element in which they have to put a number, example 213456789, or if they don't have a number, this field stays empty. This number is a unique value. Is it possible to have combined these two validations (is unique value or is empty). If possible how to achieve this?
    Just let me know.

    Kind regards, Ernst
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Standard
    In the isunique validation set the condition:
    return '{your-table___element}'!='';
    So it's only validating if the element is not empty.
     
  3. ErnstJan

    ErnstJan Member

    Level: Community
    validating is unique value or is empty

    Thanks Troester,

    Works perfect! Last question: is it possible to say this unique value only has nine numbers example: 012345678 or 993456782 (without any other character like , :?# etc) ?
    Just let me know.

    Kind regards, Ernst
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Standard
    You can add a regular expression validation (there have been some threads about validating telephon numbers).
     
  5. ErnstJan

    ErnstJan Member

    Level: Community
    validating is unique value or is empty and regular expression

    Hello Troester,

    Thanks for very quick reply! I found this regular expression and changed it a little:
    /^[0-9]{9}$/ I also added condition if field is left empty. Everything works fine now!
    I appreciate your help very much!


    Kind regards, Ernst
     

Share This Page