on 03-18-2015 12:37 PM
Hello Experts,
This is File to Proxy Scenario.
We are getting Special Characters in some fields and PI is passing those values successfully. But we want to throw Error for that.
For Example:
Field Mobile Number should only contain numeric digit.
So we used pattern: [0-9], [0-9], [0-9], [0-9], [0-9], [0-9], [0-9], [0-9], [0-9], [0-9]
But still it is passing Special Characters.
Please help in this regard.
Regards,
Sayanti Mukherjee
How are you validating the number field, Using a UDF? if so please share the code so that we can review.
This should work - var1 is your mobile number
if(var1.matches("[0-9]+"))
{
return var1;
}
else{
throw new RuntimeException("Mapping fail - invalid mobile number");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sayanti,
You can do this in two options
1) Schema validation option in ICO.
You can create the pattern for the field like "[0-9]{10}".
2) As mentioned by Hareesh, you can do it in mapping level by using UDF, if you want to restrict the length of the phone number also then use below UDF.
public String validatePhoneNumber(String phone, Container container) throws StreamTransformationException {
String regex = "\\d{10}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(phone);
if (matcher.matches()) {
return phone;
} else {
throw new RuntimeException("Mapping Error - Invalid Phone Number");
}
}
Regards,
Praveen.
Hi Sayanti,
You can define patterns in your XSD: XML Schema Restrictions/Facets
Also you can do an UDF to throw an exception () or to control this generating an alternative message via java.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.