Title: Additional Data Fields validation
Last modified: November 29, 2019

---

# Additional Data Fields validation

 *  [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/)
 * Is there a way to validate that input in Additional Data Fields are in format
   with set constraints? – Etc. a date input as m/d/y

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12189032)
 * Hi, it can be done with Javascript hooks. Do you have knowledge of Javascript?
 * Regards
 * Nickolas
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12189274)
 * Hi Nikolas
 * I have a very limited knowledge of javascript, but I do have programming experience.
   So if you point me in the right direction maybe I can solve it on my own
 * Thanks!
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12193808)
 * Okay I got it fixed with some javascript and simple RedExp.
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12193834)
 * Hi, here is sample Javascript code that you need to put below the shortcode:
 *     ```
       <script type="text/javascript>
       if(window.addEventListener) { window.addEventListener("load", wfu_check_userdata, false); }
       else if(window.attachEvent) { window.attachEvent("onload", wfu_check_userdata); }
       else { window["onload"] = wfu_check_userdata; }
       function wfu_check_userdata() {
       	Code_Initializators[Code_Initializators.length] = function(sid) {
       		var Custom_Code_Objects = {};
       		Custom_Code_Objects.pre_start_check = function (attr) {
       			if (!attr) return attr;
       			var sid = this.sid;
       			var fid = 1;
       			var WFU = GlobalData.WFU[sid];
       			var props = WFU.userdata.props[fid];
       			var result = true;
       			//get and check field value
       			var value = WFU.userdata.getValue(props);
       			return result;
       		}
       		return Custom_Code_Objects;
       	}
       	wfu_Load_Code_Connectors(1);
       }
       </script>
       ```
   
 * This code inserts a check before the upload starts. If the check passes, then
   function Custom_Code_Objects.pre_start_check should return true, otherwise it
   should return false.
 * In this line `var value = WFU.userdata.getValue(props);` I show you how you can
   get the value of the field with index **fid**.
 * Regards
 * Nickolas
    -  This reply was modified 6 years, 5 months ago by [nickboss](https://wordpress.org/support/users/nickboss/).
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12193888)
 * Hi Nickolas
 * Looks great and a lot more thought through than what I hacked out 😉
 * But I’m having some difficulties understanding where I can setup the parameters
   for the validation. Do I need to set the props value ?
 * I have this RedExp that I want it to correspond to:
    /^\d{1,3}.\d{1,20},\d{1,3}.\
   d{1,20}/
 * Thanks for all you help !
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12193905)
 * And just saw that without any changes to the code you just send, it gives:
    TypeError:
   props is undefined
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12195459)
 * Hi, strange, can I see the page myself? what is the URL?
 * Nickolas
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12195966)
 * Hi
 * Sure the url is: `https://wi-form.com/uploader/`
    and the pwd is `Nickolas`
 * The uploader only takes .obj
 * And I made a script that alerts if the user input doesn’t match `"/^\d{1,3}.\
   d{1,20},\d{1,3}.\d{1,20}/"` formatting, but as of right now the user can still
   upload even though the input doesn’t match.
 * My script is:
 *     ```
       "
       var input = document.getElementsByClassName("file_userdata_message")
       var userinput = document.getElementById("hiddeninput_1_userdata_0")
   
       input[0].addEventListener("blur", function() {
       	userinputNow = userinput.value
       	regExp = /^\d{1,3}.\d{1,20},\d{1,3}.\d{1,20}/;
           var match = regExp.test(userinputNow);
           if (match){
           	return
           }
           else if (userinputNow == 0){
           	return
           }
           else{
           	alert('Please enter valid coordinates')
           }
       });
       "
       ```
   
    -  This reply was modified 6 years, 5 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Formatting
 *  Thread Starter [masdaa](https://wordpress.org/support/users/masdaa/)
 * (@masdaa)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12197381)
 * Hi Nikolas
 * Okay got it fixed 🙂
 * Turned out that it was just because the fid was set to 1 and the userinput element
   was 0
 * From there I just implemented the RedExp and if it was not a match, it alerts(
   could be done more elegant, but it works) and returns false. Thanks for all the
   help !
 * For anyone in the future here is the working script:
    if(window.addEventListener){
   window.addEventListener(“load”, wfu_check_userdata, false); } else if(window.
   attachEvent) { window.attachEvent(“onload”, wfu_check_userdata); } else { window[“
   onload”] = wfu_check_userdata; }
 * function wfu_check_userdata() {
    Code_Initializators[Code_Initializators.length]
   = function(sid) { var Custom_Code_Objects = {}; Custom_Code_Objects.pre_start_check
   = function (attr) { if (!attr) return attr; regExp = /^\d{1,3}.\d{1,20},\d{1,3}.\
   d{1,20}/; var sid = this.sid; var fid = 0; var WFU = GlobalData.WFU[sid]; var
   props = WFU.userdata.props[fid]; var result = true; //get and check field value
   var value = WFU.userdata.getValue(props); var match = regExp.test(value) console.
   log(value) if (match) { return result; } else { alert(‘Please enter valid coordinates’)
   return false;
 *  }
 *  }
    return Custom_Code_Objects; } wfu_Load_Code_Connectors(1); }
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12201306)
 * Ok good.
 * Regards
 * Nickolas

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Additional Data Fields validation’ is closed to new replies.

 * ![](https://ps.w.org/wp-file-upload/assets/icon-256x256.png?rev=3252590)
 * [Iptanus File Upload](https://wordpress.org/plugins/wp-file-upload/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-file-upload/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-file-upload/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-file-upload/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-file-upload/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-file-upload/reviews/)

## Tags

 * [user input](https://wordpress.org/support/topic-tag/user-input/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 10 replies
 * 2 participants
 * Last reply from: [nickboss](https://wordpress.org/support/users/nickboss/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/additional-data-fields-validation/#post-12201306)
 * Status: not resolved