In Mode-Driven Power Apps, Dataverse tables' forms and business rules are crucial. The Business rules help makers apply logic and validations without writing code or creating plug-ins. Business rules provide a simple interface to implement and maintain fast-changing and commonly used rules. But we sometimes need to enforce custom logic validation using JavaScript for the Dataverse tables' forms fields validation.
This blog post will explore 8 specific use cases where regular expressions can be applied to validate user inputs in the Dataverse tables' form fields. Additionally, we will discuss a solution I built that will help you generate the necessary JavaScript code, and we will demonstrate how to attach JavaScript web resources to the fields that require validation. (Watch the Tutorial Video)
Why Client-Side Fields Input Validation with JavaScript?
Client-side validation can enhance the user experience by providing immediate feedback on input. Using JavaScript for validation offers flexibility and control over the validation logic.
- Advantages:
- Immediate Feedback: Users receive instant feedback without a server trip.
- Customization: You can create complex validation logic that OOB Business rules can't handle.
- Performance: Reduces server load as validation occurs on the client side.
Here are the 8 use cases we'll cover, using regular expressions to perform validation:
- Field Input Must be Case Sensitive (Capital Letters): Enforce that the input contains only capital letters.
- Field Input Must be Case Sensitive (Small Letters): Ensure the input consists of small letters only.
- Field Input Must Contain Only Letters: Validate that the input contains letters without numbers or special characters.
- Field Input Must End with a Specific String: Confirm that the input ends with a specific string defined by you.
- Field Input Must Start with a Specific String: Enforce that the input begins with a specific string defined by you.
- Field Input Must Match a Number Pattern (###-##-####): Validate that the input matches a specific numerical pattern.
- Field Input Must Match a Letters & Numbers Pattern (ABC-###-####): Ensure that the input conforms to a pattern combining letters and numbers.
- Field Input Must NOT Include Special Characters: Enforce that the input contains no special characters.