0

How can I apply custom validation to Infopath 2010 fields which stretches beyond the basic Rules and Templates?

I am looking to validate a custom field which needs to be validated much like a Credit Card Number. The field itself needs to be a template of ###-###-### but needs to be validated with the Luhn Algorithm like Credit Card Numbers are. I can do this with C# but am unsure of how to apply C# Validation to an Infopath field.

Is this possible, and if so how can I go about doing this?

2
  • You should edit to improve your question instead of duplicating it Also, I cannot believe that you do not know how to use search on internet Oct 10, 2012 at 1:01
  • I come to stack instead of just searching the internet because I normally receive well thought-out criticism and opinions. Not because I forgot how to use Google.
    – Lando
    Oct 10, 2012 at 16:34

2 Answers 2

2

You will need to do it in code behind in the InfoPath form.

Here is a link to that. You can still use you C# code to do it. Take a look below.

http://www.bizsupportonline.net/infopath2007/infopath-basics-3-ways-validate-data-infopath.htm

4
  • Depends on the complexity of the validation. If you can use regular expression, etc. then go with that option. From my experience, I recommend that you avoid using the InfoPath code-behind as much as possible or try not write too much logic in the code behind. Maintaining the code behind is a headache and makes your IP solution more complex and flimsy (there are some compatiblity issues as well, msdn.microsoft.com/en-us/library/bb772074.aspx). You can also write a service to do the validation for you. You can then consume this service in your IP form.
    – H A
    Oct 9, 2012 at 17:36
  • I recommend Reg Expressions also but he is trying to run an algorithm I think C# is the only way. If the algorithm is compute intensive I would query a service for the validation and let the service handle the work. Oct 9, 2012 at 17:57
  • Joseph - I believe that tutorial is only for Infopath 2007 and not 2010. Lots of those steps do not seem to line up with 2010, unless I'm wrong?
    – Lando
    Oct 9, 2012 at 21:52
  • This link is related to InfoPath 2010 and should guide you in the correct direction. blogs.msdn.com/b/infopath/archive/2010/03/18/… Oct 9, 2012 at 21:58
0

Generally speaking you can create algorithms of any complexity through Rules (including iterations using hidden fields) without code behind.

Also note that some compatibity/type of Infopath form templates like Sharepoint List Form types do not permit (client-side) code behind.

The Sharepoint List Form type with locked Main data connection /source is generated for you when/if one presses:

  • Customize Form button on ribbon having navigated to a sharepoint list in a browser
  • Sharepoint List button in File > New of Infopath Form Designer 2010

It does not mean that one cannot work with sharepoint lists in other types of IP form templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.