cancel
Showing results for 
Search instead for 
Did you mean: 

Validate Special Characters

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

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");

}

Former Member
0 Kudos

Hello Hareesh,

Thanks for sharing this code.

Regards.

Sayanti Mukherjee

former_member182412
Active Contributor
0 Kudos

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.

former_member184720
Active Contributor
0 Kudos

Please close the thread if your issue is resolved.

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

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.