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!
For my User case, the regular expression is ^\d{5}$
Inculcate this in your code as shown below:
Reach out to me if you have any questions or suggestions.
Check out other blogs, if you haven't already.
Great blog and it's so useful.
ReplyDelete