Validation for numeric values in String using X++ & strKeep() in D365 FO

Requirement

VALIDATION FOR NUMERIC VALUES IN STRING USING X++ & STRKEEP FUNCTION IN Microsoft Dynamics 365 finance & operations.

Sample Code

public static void main(Args _args)
{
str	Mobile  = "7123456789";
if (strLen(strRem(Mobile, ",")) != strLen(strKeep(strRem(Mobile, ","), "1234567890")))
{
throw error("Invalid Mobile Number");
}
else
{
info("Valid Mobile Number");
}

/// for decimal 
str	realValue = "11.20";
if (strLen(strRem(Mobile, ",")) != strLen(strKeep(strRem(Mobile, ","), "1234567890."))) // added decimal 
{
throw error("Invalid Real Value");
}
else
{
info("Valid Real Value");
}
}

One thought on “Validation for numeric values in String using X++ & strKeep() in D365 FO”

Leave a Reply