The Validate function in Power Apps is used to check whether a record (or changes to a record) complies with the validation rules defined in your data source. This function is particularly useful for ensuring data integrity before submitting or saving changes to a data source.
PowerApps – Validate() function Syntax
Validate(DataSource, DataRecord [, Column])
- DataSource: The data source that contains the validation rules.
- DataRecord: The record or changes to validate against the data source's rules.
- Column (optional): The specific column to validate. If omitted, the entire record is validated.
Notes:
- Error Messages: Customize error messages to provide clear and specific feedback to users about validation issues.
- Validation Rules: Understand the validation rules defined in your data source to effectively use the Validate function.
- Combining with Other Functions: Combine the Validate function with conditional logic and error handling functions like IfError for robust validation processes.
- Data Integrity: Ensure data integrity by validating user inputs before saving them to the data source.
- User Feedback: Provide immediate feedback to users about validation errors, improving the user experience.
- Form Validation: Integrate validation into form submission processes to prevent invalid data from being submitted.
PowerApps - Validate a Single Column
Suppose you have a data source named Employees with a column Email that has a specific format validation rule, and you want to validate the Email before saving it.
- Add a Text Input Control for Email:
- Insert a Text Input control named EmailInput.
- Add a Label Control to Display Validation Message:
- Insert a Label control named ValidationMessage.
- Set the Visible property of the Label to:
!IsBlank(ValidationMessage.Text)
- Add a Button Control to Validate Email:
- Insert a Button control named ValidateButton.
- Set the Text property of the Button to "Validate Email".
- Set the OnSelect property of the Button to:
Set(ValidationResult, Validate(Employees, {Email: EmailInput.Text}, "Email"));
If(IsBlank(ValidationResult),
Set(ValidationMessage.Text, "Email is valid"),
Set(ValidationMessage.Text, ValidationResult)
)
When the button is clicked, it validates the email entered in the EmailInput control and displays an appropriate message in the ValidationMessage label.
PowerApps - Validate Multiple Columns
Suppose you want to validate multiple columns, such as Email and PhoneNumber, before saving a record.
- Add Text Input Controls for Email and Phone Number:
- Insert a Text Input control named EmailInput.
- Insert another Text Input control named PhoneInput.
- Add a Label Control to Display Validation Message:
- Insert a Label control named ValidationMessage.
- Set the Visible property of the Label to:
!IsBlank(ValidationMessage.Text)
- Add a Button Control to Validate the Record:
- Insert a Button control named ValidateButton.
- Set the Text property of the Button to "Validate Record".
- Set the OnSelect property of the Button to:
Set(ValidationResult, Validate(Employees, {Email: EmailInput.Text, PhoneNumber: PhoneInput.Text}));
If(IsBlank(ValidationResult),
Set(ValidationMessage.Text, "Record is valid"),
Set(ValidationMessage.Text, ValidationResult)
)
When the button is clicked, it validates the Email and PhoneNumber fields and displays the validation result in the ValidationMessage label.
Suppose you have a form for adding or updating employee records, and you want to validate the data before submitting the form.
- Add a Form Control:
- Insert a Form control named EmployeeForm.
- Set the DataSource property of the form to Employees.
- Add a Button Control to Submit the Form:
- Insert a Button control named SubmitButton.
- Set the Text property of the Button to "Submit".
- Add a Label Control to Display Validation Message:
- Insert a Label control named ValidationMessage.
- Set the Visible property of the Label to:
!IsBlank(ValidationMessage.Text)
- Set the OnSelect Property of the Submit Button:
- Set the OnSelect property of the Button to:
Set(ValidationResult, Validate(Employees, EmployeeForm.Updates));
If(IsBlank(ValidationResult),
SubmitForm(EmployeeForm),
Set(ValidationMessage.Text, ValidationResult)
)
This will validate the data in the EmployeeForm before submitting it. If the data is valid, the form is submitted; otherwise, the validation message is displayed in the ValidationMessage label.