Angular UI Components Documentation
The Angular Validator checks form input against rules and shows a hint next to each invalid field. This guide adds the Angular Validator (jqxValidator) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-ngjqwidgets-ng/jqxvalidator 
In an Angular project (to start one, see Getting started with Angular), add the package with the Angular CLI. It asks for a theme and adds the styles to angular.json:
ng add jqwidgets-ng
Components are standalone: add jqxValidatorModule to the imports of the component that uses it.
import { Component } from '@angular/core';
import { jqxValidatorModule } from 'jqwidgets-ng/jqxvalidator';
@Component({
selector: 'app-root',
imports: [jqxValidatorModule],
templateUrl: './app.html'
})
export class App {}
The source of the live Default Functionality demo.
<jqxExpander [width]="350" [showArrow]="false" [toggleMode]="'none'">
<div><h3 style="padding: 0; margin: 0;">Register</h3></div>
<div style="padding: 5px;">
<jqxValidator #myValidator [rules]="rules">
<form id='form' action="./">
<table class="register-table">
<tbody>
<tr>
<td>Username:</td>
<td><jqxInput class="userInput text-input" [width]="195" [height]="22"></jqxInput></td>
</tr>
<tr>
<td>Password:</td>
<td><jqxPasswordInput #passwordInput class="passwordInput text-input" [width]="195" [height]="22"></jqxPasswordInput></td>
</tr>
<tr>
<td>Confirm password:</td>
<td><jqxPasswordInput #confirmPasswordInput class="passwordConfirmInput text-input" [width]="195" [height]="22"></jqxPasswordInput></td>
</tr>
<tr>
<td>Real name:</td>
<td><jqxInput [width]="195" [height]="22" class="realNameInput text-input"></jqxInput></td>
</tr>
<tr>
<td>Birth date:</td>
<td><jqxDateTimeInput #dateTimeInput [width]="195" [height]="22" [value]="initialDate" class="birthInput"></jqxDateTimeInput></td>
</tr>
<tr>
<td>E-mail:</td>
<td><jqxInput [placeHolder]="'someone@mail.com'" class="emailInput text-input" [width]="195" [height]="22"></jqxInput></td>
</tr>
<tr>
<td>SSN:</td>
<td><jqxMaskedInput [width]="195" [height]="22" [mask]="'###-##-####'" class="ssnInput"></jqxMaskedInput></td>
</tr>
<tr>
<td>Phone:</td>
<td><jqxMaskedInput [width]="195" [height]="22" [mask]="'(###)###-####'" class="phoneInput"></jqxMaskedInput></td>
</tr>
<tr>
<td>Zip code:</td>
<td><jqxMaskedInput [width]="195" [height]="22" [mask]="'###-##-####'" class="zipInput"></jqxMaskedInput></td>
</tr>
<tr>
<td colspan="2" style="padding-left: 100px; padding-top: 10px; padding-bottom: 10px;">
<jqxCheckBox [width]="130" id="acceptCheckBox">I accept terms</jqxCheckBox>
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 20px;">
<jqxButton #SendButton
(onClick)="sendButton()"
style="text-align: center; margin-left: 8em;"
[width]="60" [height]="25">
Send
</jqxButton>
</td>
</tr>
</tbody>
</table>
</form>
</jqxValidator>
</div>
</jqxExpander>
import { Component, ViewEncapsulation, viewChild } from '@angular/core';
import { jqxValidatorComponent } from 'jqwidgets-ng/jqxvalidator';
import { jqxPasswordInputComponent } from 'jqwidgets-ng/jqxpasswordinput';
import { jqxDateTimeInputComponent } from 'jqwidgets-ng/jqxdatetimeinput';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { jqxValidatorModule } from 'jqwidgets-ng/jqxvalidator';
import { jqxButtonModule } from 'jqwidgets-ng/jqxbuttons';
import { jqxCheckBoxModule } from 'jqwidgets-ng/jqxcheckbox';
import { jqxDateTimeInputModule } from 'jqwidgets-ng/jqxdatetimeinput';
import { jqxExpanderModule } from 'jqwidgets-ng/jqxexpander';
import { jqxInputModule } from 'jqwidgets-ng/jqxinput';
import { jqxMaskedInputModule } from 'jqwidgets-ng/jqxmaskedinput';
import { jqxPasswordInputModule } from 'jqwidgets-ng/jqxpasswordinput';
@Component({
imports: [
CommonModule,
FormsModule,
jqxValidatorModule,
jqxButtonModule,
jqxCheckBoxModule,
jqxDateTimeInputModule,
jqxExpanderModule,
jqxInputModule,
jqxMaskedInputModule,
jqxPasswordInputModule
],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css',
encapsulation: ViewEncapsulation.None
})
export class App {
readonly myValidator = viewChild.required<jqxValidatorComponent>('myValidator');
readonly dateTimeInput = viewChild.required<jqxDateTimeInputComponent>('dateTimeInput');
readonly passwordInput = viewChild.required<jqxPasswordInputComponent>('passwordInput');
readonly confirmPasswordInput =
viewChild.required<jqxPasswordInputComponent>('confirmPasswordInput');
initialDate: Date = new Date(2023, 8, 1);
sendButton(): void {
this.myValidator().validate(document.getElementById('form'));
}
rules = [
{
input: '.userInput',
message: 'Username is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.userInput',
message: 'Your username must be between 3 and 12 characters!',
action: 'keyup, blur',
rule: 'length=3,12'
},
{
input: '.realNameInput',
message: 'Real Name is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.realNameInput',
message: 'Your real name must contain only letters!',
action: 'keyup',
rule: 'notNumber'
},
{
input: '.realNameInput',
message: 'Your real name must be between 3 and 12 characters!',
action: 'keyup',
rule: 'length=2,12'
},
{
input: '.birthInput',
message: 'Your birth date must be between 1/1/1906 and 12/31/2025.',
action: 'valueChanged',
rule: (input: any, commit: any): any => {
let date = this.dateTimeInput().value();
let result = date!.getFullYear() >= 1906 && date!.getFullYear() <= 2026;
return result;
}
},
{
input: '.passwordInput',
message: 'Password is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.passwordInput',
message: 'Your password must be between 4 and 12 characters!',
action: 'keyup, blur',
rule: 'length=4,12'
},
{
input: '.passwordConfirmInput',
message: 'Password is required!',
action: 'keyup, blur',
rule: 'required'
},
{
input: '.passwordConfirmInput',
message: "Passwords doesn't match!",
action: 'keyup, focus',
rule: (input: any, commit: any): boolean => {
if (this.passwordInput().val() === this.confirmPasswordInput().val()) {
return true;
}
return false;
}
},
{
input: '.emailInput',
message: 'E-mail is required!',
action: 'keyup, blur',
rule: 'required'
},
{ input: '.emailInput', message: 'Invalid e-mail!', action: 'keyup', rule: 'email' },
{ input: '.ssnInput', message: 'Invalid SSN!', action: 'valuechanged, blur', rule: 'ssn' },
{
input: '.phoneInput',
message: 'Invalid phone number!',
action: 'valuechanged, blur',
rule: 'phone'
},
{
input: '.zipInput',
message: 'Invalid zip code!',
action: 'valuechanged, blur',
rule: 'zipCode'
},
{
input: '#acceptCheckBox',
message: 'You have to accept the terms',
action: 'change',
rule: 'required',
position: 'right:217,0'
}
];
}html, body {
width: 100vw;
height: 100vh;
padding: 0;
margin: 0;
}
.text-input {
}
.register-table {
margin-top: 10px;
margin-bottom: 10px;
}
.register-table td,
.register-table tr {
margin: 0px;
padding: 2px;
border-spacing: 0px;
border-collapse: collapse;
font-family: Verdana;
font-size: 12px;
}
h3 {
display: inline-block;
margin: 0px;
padding: 0px;
}
Options are inputs, bound with [name]="value".
Events are outputs named on plus the event name with a capital first letter. For example, validationError: This is triggered when the form is validated with some errors.
<jqxValidator (onValidationError)="onValidationError($event)"></jqxValidator>
onValidationError(event: any): void {
console.log(event.args);
}
Get the component with a signal query and call its methods. For example, hideHint: Hide all hints for a specific input.
<jqxValidator #myValidator></jqxValidator>
import { Component, viewChild } from '@angular/core';
import { jqxValidatorModule, jqxValidatorComponent } from 'jqwidgets-ng/jqxvalidator';
@Component({
selector: 'app-root',
imports: [jqxValidatorModule],
templateUrl: './app.html'
})
export class App {
readonly myValidator = viewChild.required<jqxValidatorComponent>('myValidator');
run(): void {
this.myValidator().hideHint('#userInput');
}
}