Monday, August 1, 2022

Validate User input data using Regular Expressions in Business Central using AL

 Hi Reader, 

Data is a crucial part of a Database and should be stored correctly and in the right format. But how do you make sure that users will not make any manual errors for the new customized fields? For example, if an E-mail is to be sent, the E-mail entered by the user should be in the right forward or valid so that emails are sent correctly. 

For scenarios like these, regular expression comes handly. 

Business Central provides an easy capability to use regular expressions and validate the User Input. 

Learn how to Create Regular Expressions: 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

Easily Create Regular Expressions to use in your Code:

https://www.autoregex.xyz/ - Thanks to Erik Hougaard for discovering this amazing application!

(This is what I am going to use today in my example, as I am no expert in this subject ;D)

Let's begin!

User Case: Pincode should be exactly 5 characters and should not have any alphabet. 

https://www.autoregex.xyz/ converts your text to Regex. How cool is that!


Validate your Regular expression on: https://regex101.com/

For my User case, the regular expression is ^\d{5}$

Inculcate this in your code as shown below:



This was a simple example for demo purposes. You can make complex regular expressions and validate the format of input data and avoid data correction :D

Reach out to me if you have any questions or suggestions. 

Check out other blogs, if you haven't already. 

Kindly suggest what else you want me to blog about. Keep following and supporting!

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you are looking for NAV/D365BC Training and/or Services!

Thank you! 

1 comment: