Author |
Message
|
balaji83it |
Posted: Sun Apr 26, 2009 11:28 pm Post subject: Field Validations using message set |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello All.
I have a requirement in which I get an input message in the form of csv. It contains various fields in which each field needs to be validated as per its data type. I have various data types like numeric of 15 characters, alphanumeric of 40 characters etc.
I need to validate them in the message set. Is there any way to validate them?
The following list shows the various data types.
• Numeric: The character set used in this type must include only digits 0-9.
• Upper Case Alphabetic: The character set used in this type includes only alphabetic characters A-Z.
• Alphabetic: The character set used in this type includes only alphabetic characters a-z and A-Z.
• Alphanumeric: The character set used in this type includes all digits 0-9 and alphabetic characters a-z, A-Z.
• Alphanumeric Special: The character set used in this type includes all digits 0-9 and alphabetic characters a-z, A-Z as well as !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ and spaces.
• Money: Numeric digits 0-9. Negative amounts are valid and are entered by adding a “-“ sign in front of them. Cents values are entered after a decimal point “.”, e.g, -250.20. Commas are not allowed.
• Percent: Valid positive number between 0-100. Values less than 0 and greater than 100 are not accepted.
• Date: The supported date formats are YYYYMMDD or MM/DD/YYYY.
• Boolean: Must be either “Y” or “N” (or empty if not required).
Thanks
K.Balaji |
|
Back to top |
|
 |
kimbert |
Posted: Mon Apr 27, 2009 12:54 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Switch on validation in your message flow.
For the details, please read about XML Schema facets. ( In a message set, facets are called 'Value Constraints' but they are really just schema facets ). |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 27, 2009 1:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kimbert wrote: |
Switch on validation in your message flow. |
kimbert wrote: |
For the details, please read about XML Schema facets. |
balaji83it wrote: |
I have a requirement in which I get an input message in the form of csv |
Can you validate a CSV message with an XML Scmema?
Anyway, doesn't invalidate your basic point i.e. use message flow validation against the message set. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Apr 27, 2009 3:05 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Vitor: The logical part of the MRM data model *is* XML schema. When you switch on validation, you are simply enabling schema validation. And validation is always performed against the logical model, not the physical format, so yes, you can validate csv ( or fixed-length, or anything else ).
Some of the numeric checking will be automatic ( provided that balaji83it defines his fields as integer or decimal ). It is obviously impossible to even parse ( let alone validate ) an integer field which contains non-numeric characters.
Checking of string fields can be handled using pattern Value Constraints or length constraints. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 27, 2009 3:12 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
kimbert wrote: |
Vitor: The logical part of the MRM data model *is* XML schema. |
Well that's something I didn't know when I woke up this morning!  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
balaji83it |
Posted: Mon Apr 27, 2009 11:27 pm Post subject: |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello Kimbert,
Thanks for your valuable suggestions. I created simple type restriction and created patterns and length constraints as required. It was nice and was working.
For a numeric field with 20 characters, I used a string and restricted its pattern to [0-9]+. And it is working. Is this the correct way or can we make use of any other way. When I used integer, it is throwing exception after the integer limit.
Thank you once again.
Balaji. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Apr 28, 2009 1:16 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
For a numeric field with 20 characters, I used a string and restricted its pattern to [0-9]+. And it is working. Is this the correct way or can we make use of any other way |
Yes, you could model it as xs:decimal. |
|
Back to top |
|
 |
balaji83it |
Posted: Tue Apr 28, 2009 3:50 am Post subject: |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello Kimbert,
Thank you. xs:decimal is also working fine.
Now I have one more small problem. As you can see above, I will get a field which can be of Date type as well. In the requirement above, my date type should follow 2 formats, i.e. to say date can come in any format (YYYYMMDD or MM/DD/YYYY) But I can specify only one date format in the date properties.
So, any ideas over this.
Thanks,
Balaji. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Apr 28, 2009 4:09 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
That's tricky. I suggest that you model it as xs:string, and do the conversion in your message flow. ESQL has some excellent date/time conversion facilities. |
|
Back to top |
|
 |
balaji83it |
Posted: Tue Apr 28, 2009 4:47 am Post subject: |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello Kimbert,
I have not a single field of Date type. I have many of them. Do I need to validate each one of them in ESQL? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Apr 28, 2009 4:54 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
If you model them as xs:string, then you can *validate* them using a pattern Value Constraint.
If you want to actually convert the string to a TIMESTAMP and process the TIMESTAMP in your message flow, then you need to use the ESQL CAST function. |
|
Back to top |
|
 |
balaji83it |
Posted: Wed Apr 29, 2009 4:22 am Post subject: |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello Kimbert,
When I take the date field as a xs:string, It seems to be difficult and Iam not able to do validations as we need to validate day, month and year. Iam using the following regular expression pattern which is not working
([1-12]/[1-31]/[1-9]{4})
Any ideas as to how to validate date when taken as string. Also it should not take a wrong date like 30/02/2009 (i.e. particular month, only 30 days and others 31 days etc.) and other leap year related conditions also.
Kimbert, it seems to be difficult if we have to validate a string as a date. Please suggest your ideas.
Thanks
Balaji |
|
Back to top |
|
 |
kimbert |
Posted: Wed Apr 29, 2009 4:31 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Well, your requirement is not exactly a common one!
Quote: |
In the requirement above, my date type should follow 2 formats |
Most messages use a single format for dates and times.
It is not hard to do this with patterns. You just need to learn how to write a regular expression. There are dozens of tutorials on the web - just Google for 'regex for date'.
Alternatively, you could use ESQL's CAST function... |
|
Back to top |
|
 |
|