X12 Data Types
EdiFabric supports the following data element types.
Numeric
Data element can include digits only.
Numeric data with implied decimal. If the decimal part is included, n shows the number of digits to the right of the implied decimal.
Leading zeros are suppressed unless needed to satisfy the minimum length of the element. If the value is negative, include a minus sign, which does not count toward the length.)
N and N0 are equivalent (it is not necessary to include the zero). This means the implied decimal is at the end of the number.
N1 means there is one digit to the right of the implied decimal. Example: The element contains the value -123, which is to be interpreted as -12.3.
N2 means there are two digits to the right of the implied decimal. Example: The element contains the value -123, which is to be interpreted as -1.23.
The DOM C# class representing numeric X12 data type is:
[Serializable()]
public class X12_N0
{
}
Decimal
Data element can include decimal point and digits only. Decimal point is optional for integers.
The number after R shows the maximum number of digits to the right of the decimal. R0 means there should be no digits to the right of the decimal.
Example: The element contains the value 150.25 and the type is R. The value being represented is also 150.25.
Example: The element contains the value 150.23 but the type is R1. The value being represented would be 150.2
Signs and decimal points do not count toward length.
The DOM C# class representing decimal X12 data type is:
[Serializable()]
public class X12_R
{
}
Alphanumeric
Data element can include any letters, digits, special characters, and control characters.
X12 notation combines the type and length as in the following examples:
an5 exactly 5 alphanumeric characters
an..5 up to 5 alphanumeric characters.
The DOM C# class representing alphanumeric X12 data type is:
[Serializable()]
public class X12_AN
{
}
Date
Date, in YYMMDD or CCYYMMDD format. CC is century.
The DOM C# class representing date X12 data type is:
[Serializable()]
public class X12_DT
{
}
Time
Time, in 24-hour clock time as follows: HHMM or HHMMSS.
The DOM C# class representing time X12 data type is:
[Serializable()]
public class X12_TM
{
}
DTP segments
Date, in CCYYMMDD or CCYYMMDD-CCYYMMDD-CCYYMMDD format. CC is century.
When a DTP segment is encountered the validator will validate all data elements with code 1251 only if there is a preceding data element with code 1250 and value D8 or RD8.
X12 Data Types Validation
By default alphabetic or alphanumeric strings are not validated for invalid characters. To enable this type of validation an implementation of a SyntxSet must be passed to either the IsValid method of EdiMessage or the X12Reader constructor (when using splitting only).
The following syntax set implementations are available:
Basic
Valid characters are:
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!&()*+,-./:;?= '""
MessageErrorContext result;
var validationResult = msg.IsValid(out result,
new ValidationSettings { SyntaxSet = new Basic()});
Extended
Valid characters are:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!&()*+,-./:;?= '""%@[]_{}\|<>~#$
MessageErrorContext result;
var validationResult = msg.IsValid(out result,
new ValidationSettings { SyntaxSet = new Extended()});
Custom
Use CustomSyntax to specify a custom set of chars for all AN data types.
MessageErrorContext result;
var validationResult = msg.IsValid(out result,
new ValidationSettings {
SyntaxSet = new CustomSyntax(new Basic().GetValidChars() + "ß")});
Regex
Use RegexSyntax to specify a custom regex for all AN data types.
MessageErrorContext result;
var validationResult = msg.IsValid(out result,
new ValidationSettings {
SyntaxSet = new RegexSyntax(new Regex("[a-zA-Z0-9 ]"))});
Override syntax set validation at the data element level
All validation is applied on type level, that is all data elements with AN type will be validated towards the specified syntax set. Sometimes it is required that a particular data element needs to be validated differently and at the same time maintain the overall syntax validation for the remainder of the data elements. This can be achieved by overriding the syntax validation at the data element level:
[DataElement("956", typeof(X12_AN), @"^[A-Z0-9 a-z,./%]*$")]
[Pos(5)]
public string TaxJurisdictionCode_05 { get; set; }
Specifying a Regex expression directly at the data element overrides the syntax set specified at the ValidationSettings for this data element only.
ISA and GS custom validation
Sometimes you'd need to apply data element validation to the control segments. They are only scarcely validated for length and EDI codes, and perhaps you'd need to validate the sender ID against a predefined set of senders.
To apply custom EDI Codes to the sender ID ISA06, you can do the following:
var codeSetMap = new Dictionary<string, List<string>>();
codeSetMap.Add("X12_ID_I06", new List<string> { "SENDER1", "SENDER2" });
isa.Validate( new ValidationSettings { DataElementCodesMap = codeSetMap });.
The ISA and SG EDI codes types that can be used for this kind of validation are:
ISA
- ISA01 - X12_ID_I01
- ISA02 - X12_ID_I02
- ISA03 - X12_ID_I03
- ISA04 - X12_ID_I04
- ISA05 - X12_ID_I05
- ISA06 - X12_ID_I06
- ISA07 - X12_ID_I05
- ISA08 - X12_ID_I07
- ISA11 - X12_ID_I65
- ISA12 - X12_ID_I11
- ISA15 - X12_ID_I14
- ISA16 - X12_ID_I15
GS
- GS01 - X12_ID_479
- GS02 - X12_ID_G02
- GS03 - X12_ID_G03
- GS07 - X12_ID_G07
- GS08 - X12_ID_G08